绑定控件的X:名称 [英] Binding a control's x:Name
问题描述
当我想补充
<TextBlock Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
Everuthing是确定的。但是,当
Everuthing is ok. But when
<TextBlock x:Name="{Binding SettingTextBlockName}" Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />
构造正在打破。
不过,我需要的所有元素不同的名字。
But I need different names in all elements.
推荐答案
X:名称
是一个特殊的属性。作为一个问题其实这不是一个属性的话,那就是该元素的名称或ID属性映射到 x上的属性:名称
。当应用于的DependencyProperty
只有绑定的工作,所以它不能继续工作时 X:名称
。它必须手动设置。
x:Name
is a special property. As a matter of fact it's not a property at all, it's an attribute that maps the name or id property of the element to x:Name
. Binding only works when applied to a DependencyProperty
, so it cannot work on x:Name
. It must be set manually.
如果你想在运行时对象来区分,可以设置标签
属性,这一切都容忍
If you want to distinguish between objects in runtime, you can set the Tag
attribute, which tolerates everything.
更多关于 X:名称
:<一href=\"http://msdn.microsoft.com/en-us/library/ms752290.aspx\">http://msdn.microsoft.com/en-us/library/ms752290.aspx
这篇关于绑定控件的X:名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!