locked
MVVM: Populate a view (with listbox) when an item from another view (with listbox) is selected RRS feed

  • Question

  • I have a list of Topics, and for each topic there are some Examples. What I want to be able to do is that when a topic is selected then I will populate another view with all Examples for that selected topic. I'm still learning MVVM so not sure how to implement such.
    Tuesday, May 14, 2013 5:12 AM

Answers

  • Hi, What you need in the background is a viewmodel bound to the view. In that viewmodel calss you need something like a dictionary or just few observable collections for topics and examples. Once you have that you can bind the topics list to the listBox on the view. And have a property "Selected Item" bound to the "SelectedItem" of the list. When "Selected Item" is set run a switch case and for each case you can have seconf listbox's itemsource set to the right choice of example's list.

    Please Mark as Answered If this answers your question Or UnMark as Answered if it did not.
    Happy to Help :)
    My Site

    • Proposed as answer by Lisa Zhu Wednesday, May 15, 2013 8:17 AM
    • Marked as answer by Lisa Zhu Monday, May 20, 2013 9:05 AM
    Tuesday, May 14, 2013 6:12 AM
  • Hi, here you have an Master/Detail with WPF sample using CollecitonView object.

    Un saludo. Miguel A. González <br/>
    Regards, Miguel A. González <br/>
    _________________________ <br/>
    Si la respuesta es correcta, márcala como correcta. También puedes votar como útil si te ha sido de ayuda<br/>
    If the answer is correct, mark it as correct. You can also vote as helpful if you have been helpful

    • Edited by Miguel A. González Tuesday, May 14, 2013 7:41 AM
    • Proposed as answer by Lisa Zhu Wednesday, May 15, 2013 8:16 AM
    • Marked as answer by Lisa Zhu Monday, May 20, 2013 9:05 AM
    Tuesday, May 14, 2013 7:35 AM

All replies

  • Hi, What you need in the background is a viewmodel bound to the view. In that viewmodel calss you need something like a dictionary or just few observable collections for topics and examples. Once you have that you can bind the topics list to the listBox on the view. And have a property "Selected Item" bound to the "SelectedItem" of the list. When "Selected Item" is set run a switch case and for each case you can have seconf listbox's itemsource set to the right choice of example's list.

    Please Mark as Answered If this answers your question Or UnMark as Answered if it did not.
    Happy to Help :)
    My Site

    • Proposed as answer by Lisa Zhu Wednesday, May 15, 2013 8:17 AM
    • Marked as answer by Lisa Zhu Monday, May 20, 2013 9:05 AM
    Tuesday, May 14, 2013 6:12 AM
  • Hi, here you have an Master/Detail with WPF sample using CollecitonView object.

    Un saludo. Miguel A. González <br/>
    Regards, Miguel A. González <br/>
    _________________________ <br/>
    Si la respuesta es correcta, márcala como correcta. También puedes votar como útil si te ha sido de ayuda<br/>
    If the answer is correct, mark it as correct. You can also vote as helpful if you have been helpful

    • Edited by Miguel A. González Tuesday, May 14, 2013 7:41 AM
    • Proposed as answer by Lisa Zhu Wednesday, May 15, 2013 8:16 AM
    • Marked as answer by Lisa Zhu Monday, May 20, 2013 9:05 AM
    Tuesday, May 14, 2013 7:35 AM