[英]Monitor a change in the property of a Telerik ScheduleView control in WPF
I have 2 properties to a class (WPF control): HorizontalOffset
and VerticalOffset
(both public Double
's).我有一个类(WPF 控件)的 2 个属性:
HorizontalOffset
和VerticalOffset
(都是公共Double
的)。 I would like to call a method whenever these properties change.每当这些属性发生变化时,我想调用一个方法。 How can I do this?
我怎样才能做到这一点? I know of one way - but I'm pretty sure it's not the right way (using a
DispatcherTimer
of very short tick intervals to monitor the property).我知道一种方法 - 但我很确定这不是正确的方法(使用非常短的滴答间隔的
DispatcherTimer
来监视属性)。
EDIT FOR MORE CONTEXT:编辑更多上下文:
These properties belong to a telerik scheduleview control.这些属性属于 Telerik scheduleview 控件。
Leverage the INotifyPropertyChanged
interface implementation of the control.利用控件的
INotifyPropertyChanged
接口实现。
If the control is called myScheduleView
:如果控件被称为
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
}
}
I know of one way ...
DispatcherTimer
我知道一种方法......
DispatcherTimer
Wow avoid that :) INotifyPropertyChange
interface is your friend.哇避免那个:)
INotifyPropertyChange
接口是你的朋友。 See the msdn for samples.有关示例,请参阅msdn 。
You basically fire an event(usually called onPropertyChanged
) on the Setter
of your properties and the subscribers handle it.您基本上会在您的属性的
Setter
上触发一个事件(通常称为onPropertyChanged
)并且订阅者处理它。
an example implementation from the msdn
goes:来自
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.