ComboBox in WPF - How to populate using MVVM

3

I am having doubts on how popular a ComboBox in WPF using the MVVM standard. Here in Stackoverflow there is a similar question to mine, but it was not answered ( # ).

I searched and saw that people mixed the Persistence layer a bit with View (code-behind). I believe they are not obeying the MVVM.

I would like to know how best to list items in a ComboBox that are in the database using the MVVM standard.

ps: If I am wrong about the MVVM pattern, please explain why.

    
asked by anonymous 07.10.2015 / 05:13

1 answer

1

Hello

I use the ViewModel to assemble the list of items I want to populate the combobox.

For example:

<ComboBox ItemsSource="{Binding ListaItens}" SelectedItem="{Binding ItemSelecionado}" />

Variables ' List ' and ' ItemSelected ' are ViewModel properties of any type. The 'Selected Item' may also be some attribute of an object.

Hugs!

    
08.10.2015 / 21:27