获取总​​是依赖项属性PropertyChangedCallback - Silverlight的 [英] Getting PropertyChangedCallback of a dependency property always - Silverlight

查看:171
本文介绍了获取总​​是依赖项属性PropertyChangedCallback - Silverlight的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖属性和回调。

I have a dependency property and a callback.

public static readonly DependencyProperty IsBusyProperty =
            DependencyProperty.Register("IsBusy", typeof(bool), 
            typeof(TabHost), new PropertyMetadata(false, IsBusyPropertyChangedCallback));

private static void IsBusyPropertyChangedCallback(DependencyObject o,
                   DependencyPropertyChangedEventArgs args)
{
/* .. */
}

假设属性值,有人再次将其设置为,回调永远不会发生。有没有什么办法来迫使回调总是发生?

Assume property value is false and someone is setting again it to false, the callback never happens. Is there any way to force the callback to happen always?

推荐答案

没有,没有。 Silverlight的调用PropertyChangedCallback只有当财产实际上已经改变。 Silverlight的原因,如果你的TabHost是无闲过,它的非忙,那么一切都没有改变,你不想用假通知,被纠缠。

No, there isn't. Silverlight calls the PropertyChangedCallback only if the property has actually changed. Silverlight reasons that if your TabHost was non-busy before, and it's non-busy now, then nothing has changed and you don't want to be pestered with a spurious notification.

如果你视得到通知住在同一个状态,你可能要重新审视你的设计:例如,调用RefreshBusyState方法,而不是依赖于更改通知。你的用例都是围绕着用户code设置属性(而不是Silverlight的DP系统设置属性)。所以,第一个问题是,这是否需要一个依赖属性?除非你需要绑定,样式或动画,它可能是一个正常的CLR属性,并且可以提高虚假变更通知中的二传手,如果你选择。如果确实需要一个DP,但你要知道,当用户code设置它,然后进行CLR属性的setter私人,并提供SetBusyState方法来代替:同样,该方法可以执行任何变化逻辑,你想要的。什么时候Silverlight重新绑定,样式或动画的属性,方法将不能运行,但如果客户端code明确地将其设置它将运行。

If you're depending on getting notifications for staying in the same state, you may want to re-examine your design: for example, invoking a RefreshBusyState method rather than relying on the change notification. Your use case revolves around user code setting the property (rather than the Silverlight DP system setting the property). So the first question is does this need to be a dependency property? Unless you need to bind, style or animate it, it could be a normal CLR property, and you can raise spurious change notifications in the setter if you so choose. If it does need to be a DP but you want to know when user code sets it, then make the CLR property setter private, and provide a SetBusyState method instead: again, that method can perform whatever change logic you want. That method won't run when Silverlight rebinds, styles or animates the property, but it will run if client code explicitly sets it.

这篇关于获取总​​是依赖项属性PropertyChangedCallback - Silverlight的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆