Reputation: 805
what I understand from this term "TwoWay" is that if any value at one end changes , it should directly get reflected to the other end, for example I have this ComboBox
<ComboBox SelectedValue="{Binding CarModel,Mode=TwoWay,IsAsync=True}" ItemsSource="{Binding carModelNames}" />
now I wanted the SelectedValue to be nothing/null, I just updated my CarModel property in the code/viewModel to be "", but that didn't work, am I missing something here ??
here is my property
public String CarModel
{
get
{
return _CarModel;
}
set
{
if (_CarModel != value)
{
_CarModel = value;
OnPropertyChanged("CarModel");
}
}
}
thanks
Upvotes: 3
Views: 4363
Reputation: 361
If the SelectedValue is changed in Code, the Control only updates, if the new value is contained in the ItemsSource. So the Collection of carModelNames must contain string.Empty or it would not be a valid Selection.
Upvotes: 2
Reputation: 1205
The propert carModelNames should be of type collection you are binding to combobox..And must use OnPropertyChange in the setter... And it would be better to use seletedItem instead of selected value..
Upvotes: 0
Reputation: 7968
look here ComboBox.SelectedValue not updating from binding source
you can use SelectedIndex
or SelectedItem
instead
Upvotes: 4