3

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

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Musaab
  • 805
  • 2
  • 13
  • 30

3 Answers3

4

look here ComboBox.SelectedValue not updating from binding source

you can use SelectedIndex or SelectedItem instead

Community
  • 1
  • 1
Navid Rahmani
  • 7,848
  • 9
  • 39
  • 57
2

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.

Jörg Reichardt
  • 361
  • 5
  • 14
0

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..

Syeda
  • 1,215
  • 11
  • 23
  • carModelNames is an ObservableCollection , I changed it to SelectedItem , see my edit on the first post to see the property I'm binding to – Musaab Jun 18 '11 at 21:05
  • @Musab: Your property name is GlassType and and the selected value property u gave in xaml is CarModel it should be GlassType.... – Syeda Jun 19 '11 at 03:50
  • yeah , I just copied the wrong property, going to fix that in a second , it could be considered a typo error – Musaab Jun 19 '11 at 06:20
  • NO , I had to changed my strategy , but I've got to tell you, these 4.0 ComboBox has serious issues and very buggy – Musaab Jun 19 '11 at 14:17