WPFを使用してバインドを実行するのに問題があります。データバインディングでUI要素が更新されない
私はこれに似ているモデルクラスを持っている:
public class DataModel
{
private double _temp;
public double Temperature
{
set
{
_temp= value;
OnPropertyChanged("Temperature");
}
get { return this._temp; }
}
}
このモデルは、私が今DataViewModelと呼ばれる別のクラスでのDataModelオブジェクトのリストを持っているクラスBaseDataModel
public abstract class BaseDataModel
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
}
から導出されリストの名前は「値」です。
どこかにリストの上:
DataViewModel model = new DataViewModel();
自体結合、私は、実行時に動的に作成されたデする必要があり、ユーザーコントロールを持っているそのクラス以上のクラスでは、したがって、結合は、次のように背後にあるコードで行われます。
curbinding = new Binding();
curbinding.Source = model.Values;
curbinding.Path = new PropertyPath("Temperature");
curbinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
myTextBox.SetBinding(TextBox.TextProperty, curbinding);
私は、PropertyChangedが発生したことを知っていますが、テキストボックスの値は更新されません。なぜ私は理解できないのですか?最初にbindigを作成すると、テキストボックスのテキストが更新されますが、Temperatureの値を変更しても何も起こりません。 私は何か考えていませんでしたか?
私は、アプリケーションには他にもたくさんのクラスがあり、より複雑であると言わざるを得ませんが、私が言ったように、値は一度更新されます。
...私は単純にINotifyPropertyChangedの実装をするのを忘れて、コメントを読んでいない場合は? – mtijn
私は愚かです...私はちょうどその部分を削除して、それについてもう一度考えたことはありませんでした... soloutoutは、このようにINotifyPropertyChangedから派生しました:BaseDataModel:INotifyPropertyChanged ありがとう! :) – peer