我有例如屬性是這樣的:如何阻止分配價值二傳手在WPF
private string foobar;
public string Foobar
{
get
{
return this.foobar;
}
set
{
if (value != this.foobar)
{
// here I want to check if value is correct
if(value != something)
{
this.foobar = value;
this.NotifyPropertyChanged("Foobar");
}
else
{
value = null;
this.foobar = null;
this.NotifyPropertyChanged("Foobar");
}
}
}
}
物業綁定(MVVM)到列表視圖: SelectedItem="{Binding Foobar, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}
。
而當用戶更改列表中的值時,selecteditem被更改並且setter中的值被設置。我的代碼是好的,當用戶選擇不正確的值,賦值和foobar null分配。但在WPF中仍然顯示選定的值。當我在getter中設置斷點時,我可以看到它也返回null。如何刷新WPF清除在ListView中選定的值?它應該像開始時一樣空虛。
感謝
因此它適用於普通值,但不適用於'null'? – JGaarsdal
不適用於任何 – Robert