我有一個與SelectedItem組合框。如果我選擇一個項目,我的設置器會進行一些計算,也許我想將值重設爲原來的值。不幸的是,我的觀點並沒有更新。我的c#ComboBox在選擇一個項目後不會調用getter。爲什麼?
我有以下組合框:
<ComboBox BorderThickness="0" VerticalAlignment="Center" Margin="2,0"
DisplayMemberPath="Name"
ItemsSource="{Binding ItemsVS.View}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}" >
</ComboBox>
這裏是我的ViewModel的屬性:
private CollectionViewSource _itemsVS;
public CollectionViewSource ItemsVS
{
get { return _itemsVS; }
set
{
_itemsVS = value;
if(PropertyChanged!=null)
PropertyChanged(this, new PropertyChangedEventArgs("ItemsVS"));
}
}
private ItemViewModel _selectedItem;
public ItemViewModel SelectedItem
{
get
{
// after setting the old value in the setter the getter is not called
// and the view is not refreshed
return _selectedItem;
}
set
{
var old = _selectedItem;
_selectedItem = value;
// After some logic I want to have the old value!!!!!!!!!!!!!!
_selectedItem = old;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("SelectedItem"));
}
}
如果設置該屬性回到它的原始值,你已經調用之前'PropertyChanged',什麼是刷新?什麼也沒有變。 – 2014-10-29 15:44:04
請使用WPF或ASP或任何其他標籤標記您的問題! – TaW 2014-10-29 15:46:01
@BenRobinson真正的話題有點複雜。也許我不想設置「價值」和「舊」。 – koalabruder 2014-10-29 15:56:04