简体   繁体   English

绑定控件的x:名称

[英]Binding a control's x:Name

When I add 当我添加

    <TextBlock  Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />    

Everuthing is ok. Everuthing还可以。 But when 但当

 <TextBlock x:Name="{Binding SettingTextBlockName}"  Text="{Binding SettingName}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" />

constructor are breaking. 构造函数正在破碎。

But I need different names in all elements. 但我需要在所有元素中使用不同的名称。

x:Name is a special property. x:Name是一种特殊属性。 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 . 事实上,它根本不是属性,它是一个将元素的name或id属性映射到x:Name属性。 Binding only works when applied to a DependencyProperty , so it cannot work on x:Name . 绑定仅在应用于DependencyProperty ,因此它无法在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. 如果要在运行时区分对象,可以设置Tag属性,该属性可以容忍所有内容。

more on x:Name : http://msdn.microsoft.com/en-us/library/ms752290.aspx 更多关于x:Namehttp//msdn.microsoft.com/en-us/library/ms752290.aspx

You should use FrameworkElement.Tag property, according to MSDN 根据MSDN,您应该使用FrameworkElement.Tag属性

FrameworkElement.Tag gets or sets an arbitrary object value that can be used to store custom information about this element. FrameworkElement.Tag获取或设置一个任意对象值,可用于存储有关此元素的自定义信息。

What use is the Tag property in .net .net中的Tag属性有什么用处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM