locked
how to apply styles dynamically in MVVM? RRS feed

  • Question

  • I want to change style of a listbox item dynamically based on the response from service call .How to do it in MVVM .Please explain with an example if possible.
    Friday, May 10, 2013 4:59 AM

Answers

  • In general, what you'd do is define your styles as states in the VSM, and then when you get your response, call myListBox.GoToState(). There's an example in the documentation for the method, which you'll find here.

    Rebecca M. Riordan

    • Proposed as answer by Can Bilgin Tuesday, May 14, 2013 2:42 PM
    • Marked as answer by Jesse Jiang Wednesday, May 15, 2013 4:52 AM
    Tuesday, May 14, 2013 12:16 PM

All replies

  • The recommended (and simplest) way to change styles dynamically is to use the VisualStateManager. Out of the box, the ListBox defines Normal, Disabled, Focused and Unfocused states, but it's pretty straightforward to add new states--you just need to call VisualStateManager.GoToState()--but exactly where you want to do that depends on your exact situation.

    Do you want to change the state when the service responds, or based on a particular value it returns?


    Rebecca M. Riordan

    Friday, May 10, 2013 11:26 AM
  • I want to change the listbox item style based on the service response.how to do it ?can u explain with an example?

    Monday, May 13, 2013 7:36 AM
  • In general, what you'd do is define your styles as states in the VSM, and then when you get your response, call myListBox.GoToState(). There's an example in the documentation for the method, which you'll find here.

    Rebecca M. Riordan

    • Proposed as answer by Can Bilgin Tuesday, May 14, 2013 2:42 PM
    • Marked as answer by Jesse Jiang Wednesday, May 15, 2013 4:52 AM
    Tuesday, May 14, 2013 12:16 PM