カウンタの変更によって発生する予定のイベントを実行したいとします。毎回c#イベントのカウンタの変更
int counter;
が値を変更すると、イベントが発生します。 私はMSDNからのようなものがあります。
public class CounterChange:INotifyPropertyChanged
{
private int counter;
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
public CounterChange()
{
}
public CounterChange(int value)
{
this.counter = value;
}
public int Counter
{
get { return counter; }
set
{
counter = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged("Counter");
}
}
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
をしかし、次は何見当がつかない。プログラムからのインクリメントをどのようにして、これらのイベントにメソッドを接続するか。
が重複する可能性のように、このクラスを使用します(http://stackoverflow.com/questions/2448487/how- [C#でイベントをディスパッチする方法] –
あなたの質問に含まれていない情報には、このイベントを処理するコードの説明があります。たとえば、イベントハンドラを自分で作成しているのですか、プロパティをUIにバインドしていますか?上に示したコードサンプルは、WPF/SL(およびその他の汎用フレームワーク)に固有です。 –