问题
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.
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/19225437/binding-a-controls-xname