silverlight屬性改變事件通知
阿新 • • 發佈:2017-06-21
void property att lap str ring nbsp callback ebo
工作中遇到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 = newView CodeBinding(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("Text", this.txtMain,(d,e)=>MessageBox.Show("Text changed")); RegisterForNotification("Value", this.sliderMain, (d, e) => MessageBox.Show("Value changed"));View Code
silverlight屬性改變事件通知