I have a attached property which name is "Translate". I set the property like this:
<Label Target="{Bi开发者_运维百科nding ElementName=UserName}"
Content="User Name"
Extensions.Translate="true"/>
I get the Target value in the property changed event handler and it is null. But I set it in the XAML. Why is it null?
Thanks.
Binding doesn't occur until later in the process of loading the UI so at the point that your local value of "true" is being applied the Binding has yet to be evaluated. You need to postpone the check of the Target value until after the Binding has been updated. This should get you started in the Translate PropertyChanged handler:
Label label = dObj as Label;
if (BindingOperations.IsDataBound(label, Label.TargetProperty))
{
Binding.AddTargetUpdatedHandler(label, (sender, args) =>
{
UIElement element = label.Target;
// do something with element
});
}
精彩评论