1

バックグラウンド:

Numericupdown があり、その 'Value' プロパティはオブジェクトのプロパティ (もちろん Decimal) にバインドされています。オブジェクトのクラスは INotifyPropertyChanged を実装し、プロパティの値が変更されると propertychanged イベントが発生し、バインディングは updatemode.OnPropertyChanged に設定されます。

private System.Windows.Forms.BindingSource myClassbindingSource;

私のフォームの OnLoad には、次のものがあります。

myClassbindingSource.Add( MyObject1 ); //(MyObject1 is an instance of MyClass)
base.OnLoad( e );

自動生成されたバインディング (DataBinding の詳細プロパティ 'Data Source Update Mode' を 'OnPropertyChanged' に変更した後):

this.NumericUpDown1.DataBindings.Add(new System.Windows.Forms.Binding(
    "Value", this.myClassBindingSource, "MyProperty", true, 
    System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));

私のクラス:

public class MyClass : INotifyPropertyChanged {

    private Decimal myValue;

    public Decimal MyProperty{
    get { return myvalue; }
    set { 
        myvalue = value;
        NotifyPropertyChanged( "MyProperty" );
    }

    ...

    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged( String info ) {
      var pceHandler = PropertyChanged;
      var pceArgs = new PropertyChangedEventArgs( info );
      if( pceHandler != null )
        pceHandler( this, pceArgs );
    }
}

問題:

現在、オブジェクトのプロパティがコードの他の部分から変更された場合、NumericUpdown は新しい値を表示していません。

コードをデバッグすると、プロパティが変更されると、PropertyChanged イベントが発生し、NUD の「Value」プロパティが適切な値を取得しますが、「Text」プロパティのデフォルト値は「0.000」です。

チェックボックスとブール値、ラベルと文字列など、バインディングが正常に機能する他のコントロールがあります。しかし、私の NUD は Decimal にバインドされていません。

質問:

「値」プロパティが更新されたときに「テキスト」プロパティを更新して、適切な値が表示されるようにするにはどうすればよいですか? というか、'Text' プロパティが更新されないのはなぜですか? これがどのように処理されるかを制御できるプロパティはありますか?

4

0 に答える 0