silverlight属性改变事件通知

2021-07-19 18:07

阅读:612

标签:bsp   span   over   his   text   val   事件通知   ide   ons   

工作中遇到silverlight本身没有提供的某些属性改变事件,但又需要在属性改变时得到通知,Google搬运stack overflow,原地址

技术分享技术分享
 /// 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);
    }
View Code
技术分享技术分享
RegisterForNotification("Text", this.txtMain,(d,e)=>MessageBox.Show("Text changed"));
RegisterForNotification("Value", this.sliderMain, (d, e) => MessageBox.Show("Value changed"));
View Code

 

silverlight属性改变事件通知

标签:bsp   span   over   his   text   val   事件通知   ide   ons   

原文地址:http://www.cnblogs.com/missile/p/7058138.html


评论


亲,登录后才可以留言!