Musaab
Musaab

Reputation: 805

Binding ComboBox twoway mode isn't working?

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

Answers (3)

J&#246;rg Reichardt
J&#246;rg Reichardt

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

Syeda
Syeda

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

Navid Rahmani
Navid Rahmani

Reputation: 7968

look here ComboBox.SelectedValue not updating from binding source

you can use SelectedIndex or SelectedItem instead

Upvotes: 4

Related Questions