WPF Combobox - How to fill in using MVVM

Asked

Viewed 449 times

3

I’m having doubts about how popular a WPF Combobox using the MVVM standard. Here at Stackoverflow there is a similar question to mine, however, has not been answered (I would like a brief explanation of how to fill a combobox in MVVM standard).

I researched and saw that people mixed a little the Persistence layer with the View (code-Behind). I believe they are not obeying the MVVM.

I wanted to know how to best list items in one ComboBox that are in the database using the MVVM standard.

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

1 answer

1


Hello!

I use the Viewmodel to assemble the list of items I want to popular the combobox.

For example:

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

The variables 'Listitems' and 'Itemselected' are properties of Viewmodel of any type. The 'Itemselected' can also be some attribute of an object.

Hugs!

  • Very cool! Eventually I discovered on this website. Thank you very much!

  • 1

    I don’t know how experienced you are with WPF. But this site helped me a lot in the beginning: link. It is very quiet to understand, and has many explanations of components. Hugs and success!!

  • I also use this site, but I didn’t find what I wanted on it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.