views:

207

answers:

1

Hi,

I'm using WPF/MVVM and am having a binding issue with a ComboBox - any help appreciated!

Heres my Combo ...

<ComboBox Name="ComboBoxAvailableCriteria" Width="255" ItemsSource="{Binding AvailableCriteria}" DisplayMemberPath="SearchableAttribute.Name" />

And heres my ViewModel ...

    private List<SearchCriteria> _availableCriteria;
    public List<SearchCriteria> AvailableCriteria
    {
        get { return _availableCriteria; }
        set
        {
            if (_availableCriteria == value) return;
            _availableCriteria = value;
            OnPropertyChanged("AvailableCriteria");
        }
    }

    public void RemoveCriteria(SearchCriteria searchCriteria)
    {
        _availableCriteria.Remove(searchCriteria);
        OnPropertyChanged("AvailableCriteria");
    }

My issue is that although RemoveCriteria removes the item from the list, it does not update the ComboBox on the View. Can anyone assist?

Thanks,

Andy

+2  A: 

You should use an ObservableCollection instead of a List in your ViewModel.

sixlettervariables
nice one, thanks for your help
Andy Clarke
Learning about ObservableCollection is the first step towards never leaving WPF :D
sixlettervariables