Pergunta

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

Foi útil?

Solução

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.

Outras dicas

You could probably bind a list of a custom class to the panorama ite . The custom class contains a title and/or description and a page class.

You can maintain your views in your main viewmodel.

Another solution would be adding the items in xaml and using the same viewmodel for the whole panorama item control. With a property you can control the visibility of each item.

Like Bryant said: there are so many solutions. It depends on your application and requirements... :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top