Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding a control's x:Name

Tags:

c#

binding

wpf

xaml

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.

like image 823
struggleendlessly Avatar asked Aug 10 '26 16:08

struggleendlessly


1 Answers

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

like image 108
CKII Avatar answered Aug 12 '26 07:08

CKII



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!