複雑なプロパティ タイプを持つ ViewModel があり、ビューをこのオブジェクトのネストされたプロパティにバインドしたいと考えています。
私のViewModelは実装INotifyPropertyChangedしています(または正確BaseViewModelに実装しています)。親プロパティのクラスが実装されていませんINotifyPropertyChanged。
クラス Car は を実装していませんINotifyPropertyChanged。しかし、私はプロパティを変更しているのではなく、プロパティManufacturerを変更しているので、イベントが値の更新をトリガーするMyCarPropertyことを期待していますか?OnNotifyPropertyChanged
親プロパティの値を更新すると、ネストされたプロパティが更新されません。この機能を実装する方法を教えてください。
ビューモデル
public class ViewModel : BaseViewModel
{
private Car _myCarProperty;
public Car MyCarProperty
{
get { return _myCarProperty; }
set
{
if (value == _myCarProperty) return;
_myCarProperty = value;
OnPropertyChanged();
}
}
}
ビューでのバインディング
<TextBlock Text="{Binding Path=MyCarProperty.Manufacturer}" />
ビューの値を変更MyCarPropertyしても更新されません。
助けてくれてありがとう!
編集: OnPropertyChanged() 実装
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion INotifyPropertyChanged