Search code examples
mvvmwindows-phonepanorama-controldynamic-usercontrols

Add/remove usercontrol in panorama item using MVVM - Windows Phone


I have a panorama app that has two panorama items so far, "recent" and "popular." These get populated with data using binding from a viewmodel. I would like to add a third ("search") panorama item that initially shows just a text box and a button.

When the user inputs text and clicks on the button, I want the text box and button to be replaced with the ListBox control that shows the search results.

I cannot find any examples on how to do this using the MVVM pattern. I am not using a MVVM framework and would like not to since I am just learning all this.

If you can explain or better, point me to examples that will allow me to do this, I would very much appreciate the help. If I left out any required info in my request, please let me know.

Sincerely,

Kamal


Solution

  • Typically for something like this you would have a property in your ViewModel that would tell the view what to show. You have lots of different options for how you could do this.

    One option would be to have a Results property that your list box is bound to. Put the textbox and button in a Grid and bind the Visibility property of the grid to a property that is Visible is there are no results and not visible if there are.

    Lots of different ways to do this.

    Examples here and here.