I am working on a dynamic search view wherein clicking a button should add a new row containing 3 combobox and 2 textboxes.
How should I go about doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you really want to do mvvm , try to forget “how can I add controls”. You don’t have to, just think about your viewmodels – WPF create the contols for you 🙂
In your case lets say we have a SearchViewModel and a SearchEntryViewmodel.
Till now you dont have to think about usercontrols/view. In your
SearchViewyou create anItemsControland bind theItemsSourcetoMySearchItems.You see now all of your
SearchEntryViewmodelsin theItemsControl(just the ToString() atm).To fit your requirements to show every SearchEntryViewmodel with 3Comboboxes and so on you just have to define a DataTemplate in your Resources
That’s all 🙂 and you never have to think about “how can I add controls dynamically?”. You just have to add new
SearchEntryViewmodelto your collection.This approach is called Viewmodel First and I think it’s the easiest way to do MVVM.