Silverlight:如何接收继承的DependencyProperty中的更改通知

Silverlight:如何接收继承的DependencyProperty中的更改通知,第1张

概述我有一个控制继承自(你猜到它)控制. 每当更改FontSize或Style属性时,我都希望收到通知.在 WPF中,我将通过调用DependencyProperty.OverrideMetadata()来执行此 *** 作.当然,有用的东西在Silverlight中没有任何地方.那么,怎么可能会收到这种类型的通知? 我认为这是一个更好的方法.仍然需要看到利弊. /// Listen for change o 我有一个控制继承自(你猜到它)控制.
每当更改FontSize或Style属性时,我都希望收到通知.在 WPF中,我将通过调用DependencyProperty.OverrIDeMetadata()来执行此 *** 作.当然,有用的东西在Silverlight中没有任何地方.那么,怎么可能会收到这种类型的通知?解决方法 我认为这是一个更好的方法.仍然需要看到利弊.

/// Listen for change of the dependency property    public voID RegisterForNotification(string propertyname,FrameworkElement element,PropertyChangedCallback callback)    {        //Bind to a depedency property        Binding b = new Binding(propertyname) { Source = element };        var prop = System.windows.DependencyProperty.Registerattached(            "ListenAttached"+propertyname,typeof(object),typeof(UserControl),new System.windows.PropertyMetadata(callback));        element.SetBinding(prop,b);    }

现在,您可以调用RegisterForNotification注册一个元素的属性的更改通知,如.

RegisterForNotification("Text",this.txtMain,(d,e)=>MessageBox.Show("Text changed"));RegisterForNotification("Value",this.slIDerMain,e) => MessageBox.Show("Value changed"));

在同一个http://amazedsaint.blogspot.com/2009/12/silverlight-listening-to-dependency.html上看到我的帖子

使用Silverlight 4.0测试版.

总结

以上是内存溢出为你收集整理的Silverlight:如何接收继承的DependencyProperty中的更改通知全部内容,希望文章能够帮你解决Silverlight:如何接收继承的DependencyProperty中的更改通知所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1003538.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存