Search code examples
c#windows-phone-7mvvmmvvm-light

a thought on mvvm structure building


I developed an app on windows phone using c# and xaml.

I want to change my own project to mvvm style. when i do the structure building, i face a question:

one business logic in my app is when the user changes the category via the listbox, i will change the colour of the controls in current page.

This is easy when using the code-behind, I just write a helper method which I can run when the user triggers the finish event.

if (category==1){
  grid.color = red;
  button.color = red;
  listbox.color = red;}
else if (category==2){
  grid.color = blue;
  button.color = blue;
  listbox.color = blue;}

But how to implement this in mvvm style? In mvvm, how can I change a bunch of binding at one time?


Solution

  • First, you would bind a Property in your View Model to the Selected Item of the ListBox.

    You would then bind the Color property of the Controls to that some Property in the View Model. You'll also need to specify a ValueConverter to convert from the Item to a Color.