简体   繁体   中英

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. 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. 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.

more on x:Name : http://msdn.microsoft.com/en-us/library/ms752290.aspx

You should use FrameworkElement.Tag property, according to MSDN

FrameworkElement.Tag gets or sets an arbitrary object value that can be used to store custom information about this element.

What use is the Tag property in .net

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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