开发者

Attached property problem

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
        });
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜