[英]Monitor a change in the property of a Telerik ScheduleView control in WPF
我有一個類(WPF 控件)的 2 個屬性: HorizontalOffset
和VerticalOffset
(都是公共Double
的)。 每當這些屬性發生變化時,我想調用一個方法。 我怎樣才能做到這一點? 我知道一種方法 - 但我很確定這不是正確的方法(使用非常短的滴答間隔的DispatcherTimer
來監視屬性)。
編輯更多上下文:
這些屬性屬於 Telerik scheduleview 控件。
利用控件的INotifyPropertyChanged
接口實現。
如果控件被稱為myScheduleView
:
//subscribe to the event (usually added via the designer, in fairness)
myScheduleView.PropertyChanged += new PropertyChangedEventHandler(
myScheduleView_PropertyChanged);
private void myScheduleView_PropertyChanged(Object sender,
PropertyChangedEventArgs e)
{
if(e.PropertyName == "HorizontalOffset" ||
e.PropertyName == "VerticalOffset")
{
//TODO: something
}
}
我知道一種方法......
DispatcherTimer
哇避免那個:) INotifyPropertyChange
接口是你的朋友。 有關示例,請參閱msdn 。
您基本上會在您的屬性的Setter
上觸發一個事件(通常稱為onPropertyChanged
)並且訂閱者處理它。
來自msdn
的示例實現如下:
// This is a simple customer class that
// implements the IPropertyChange interface.
public class DemoCustomer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
public string CustomerName
{
//getter
set
{
if (value != this.customerNameValue)
{
this.customerNameValue = value;
NotifyPropertyChanged("CustomerName");
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.