質問
クラス(WPF制御):HorizontalOffset
とVerticalOffset
(Public Double
)には、2つのプロパティがあります。これらのプロパティが変更されるたびにメソッドを呼び出したいと思います。これどうやってするの?私は一方的なことを知っています - しかし、私は正しい方法ではない(プロパティを監視するための非常に短いティックインターバルのDispatcherTimer
を使用して)正しい方法ではありません。
編集詳細の場合:
これらのプロパティは、Telerik ScheduleViewコントロールに属します。
解決
制御のINotifyPropertyChanged
インタフェースの実装を活用します。
Controlが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
WOWそれを回避します:)
INotifyPropertyChange
インターフェースはあなたの友達です。サンプルのMSDN 。あなたは基本的にあなたのプロパティの
onPropertyChanged
でイベント(通常はSetter
と呼ばれます)を発射し、加入者はそれを処理します。
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"); } } } }
所属していません StackOverflow