views:

670

answers:

2

When creating a control style & template in Blend for a WPF application, I want to take advantage of the Visual State Manager. How do I do this?

Whenever I right-click over the button and select Edit Template, Create Empty ... nothing shows up in the States panel.

When I do the same for Silverlight application, the typical states show up in the States panel.

Is this possible in Blend somehow? Or do I have to add all of this xaml manually?

+2  A: 

The answer depends on what version of Blend you are using.

In Blend v2.0 with SP1 installed (and the WPFToolkit installed), you needed a registry key to even enable the Visual State Manager (VSM). See this post for more info. But the States panel was empty when creating a new template.

In Blend v3.0, you didn't need the tricky registry key, but once again, the States panel is still empty. Here is a Blend forum post that confirms this is how it works.

In Blend v4.0 (go download the preview here) ... the good news is that they fixed this! The states show up in the States panel and the necessary xaml gets spit out ... if you modify any of the states.

Note:

Blend 4 creates Visual Studio 2010 solutions & projects and targets WPF 4.0. You can always retarget to an older version of WPF, if that is what you are after, or simply copy/paste the xaml out.

cplotts
+1  A: 

To be clear, with Blend 3, you must have the WPF toolkit installed on your machine as a pre-requisite.

The default controls shipping with WPF, however, do not use VSM yet. The main use case in WPF applications (unlike Silverlight, where all controls use States) is UserControls, where you can create your own state groups and states as part of the control. This is actually immensely useful, and something I would not want to live without any more :-)

Christian Schormann
Good point! I had forgotten to mention that (about also needing the WPF toolkit for Blend 3).I also love using VSM with UserControl(s) ... and I agree ... totally useful!
cplotts