Combobox update linked to Binding

1

I'm working with the MVVM pattern, so far so good, I have a PessoaViewlModel class.

In it I have a property IEnumerable<Municipio> Municipios , which shows me all the municipalities, according to UF(Unidade federativa Selecionada) .

When I initialize WPF from person record, it loads the municipalities, but after initialization I pass the command so that in the list are only the municipalities that correspond to UF. In my property Municipios of PessoaViewModel is correct, however the items in the combobox does not follow the existing information in Municipios to which combobox is bound to binding.

    
asked by anonymous 27.05.2014 / 19:50

2 answers

0

I was able to solve the problem, I was actually working with the MvvmMicro frmaework, I switched to the Mvvm light toolkit and it worked normally. Highlighting that all the tips they gave me tried and did not work.

    
05.06.2014 / 19:27
2

Use ObservableCollection<Municipio> instead of IEnumerable<Municipio> . Whenever an element enters the exits or the list, a notification is generated, causing the screen to modify its elements.

Do not create a new object because it will lose the connection, unless your class implements the INotifyPropertyChanged " and you have the property

ObservableCollection<Municipio> _municipios;
public ObservableCollection<Municipio> Municipios
{
    get { return _municipios; }
    set 
    {
        if(_municipios != value) 
        {
            _municipios = value;
            PropertyChanged(this, new PropertyChangedEventArgs("Municipios"));
        }
    }
}

This way you can still use IEnumerable<Municipio> but it will not work if you add some new element to the list.

    
28.05.2014 / 19:11