VisualStateManager usage

Dec 2, 2008 at 1:55 PM
Hi,

I have a question for the experts out there!! I have just been looking at the VSM in the tool kit and I was wondering; is it intended that the VSM will replace Triggers when wanting to customize controls? (I don't know much about Triggers either mind you!!)

For example: If I wanted to use the DataGrid but have the rows highlight when the mouse goes over (not selecting) them, can this be done using the VSM? Also, if I wanted to change the sort of move over color of a button, should I use the VSM or a Trigger in a Style?

Thanks for your help.

Graham
Dec 2, 2008 at 5:22 PM
The VSM was invented for Silverlight to make up for the fact that Silverlight doesn't have real triggers. The VSM, in my opinion, is a bit of a hack. Partly because it's trying to give you the functionality that the much-more-powerful triggers give you, and party because it really only works for quite trivial scenarios/controls. You should use triggers if they are available to you.
Coordinator
Dec 2, 2008 at 9:52 PM
VSM was first released in Silverlight, and Silverlight does not have triggers. However, we do view both as having a place in templating. VSM, generally, is about allowing designers to define the look of visual states and transitions between these states. Currently, it is up to the developer to switch between these states, and this can only be done in code. Many of the state transition methods written out there, however, look very much like template trigger definitions. We are working on a unifying story here but don't have anything to announce yet.

The main message is that both will be around in the future and have their place:
  • Use VSM when you are working like a designer on distinct visual states and transitions.
  • Use Triggers when you are working like a developer with property values and dependencies.

These aren't hard rules, just generalities.

Hope that helps,
Ben

Dec 3, 2008 at 6:35 AM
Thanks guys for your help and advice.

Graham
Coordinator
Dec 3, 2008 at 10:58 PM
Edited Dec 4, 2008 at 12:39 AM
Here's a link to a sample that uses VSM with DataGrid.  It's a good base that illustrates how this can be done using the WPFToolKit.

http://msdnrss.thecoderblogs.com/2008/11/04/wpf-vsm-and-datagrid-sample/