views:

468

answers:

2

I have built a custom control that extends content control. Within this I have a parts and states model that is working fine.

I then use this as the root of my xaml(placing the code in the templates folder in Blend)

Everything works fine, I can open a new 'DaveControl' and get the functionality that I want.

However, If I then add make some visual states here, such as alertOnScreen and try to use the visualstatemanager it doesn't work.

infact there are no states listed.

The Behaviour in SL3 GotoVisualState works fine though!

How can I get the visual state to work in code?

A: 

Have you added the set of available states as a set of TemplateVisualState attributes on the class? Blend uses these to configure its list of available states.

Your class should generally look like this:-

[TemplateVisualState(Name = "MyGroup1State1", GroupName = "MyGroup1")]
[TemplateVisualState(Name = "MyGroup1State2", GroupName = "MyGroup1")]
[TemplateVisualState(Name = "MyGroup2State1", GroupName = "MyGroup2")]
[TemplateVisualState(Name = "MyGroup2State2", GroupName = "MyGroup2")]
[TemplatePart(...)]
[TemplatePart(...)]
public class MyControl : ContentControl
AnthonyWJones
Anthony,The visual states for the control there work. The control is basically a custom container... I use it as the root element in my xaml File->New Dave Control (that way I can derive from the class without the partial class problem). Now say this control has a button on it 'Add Address' that requires something to move on stage, custom to this instance.... hence my problem.Thanks for the response, with the title I am sure it will help someone.
DavidA
+2  A: 

So the solution is the following: Use Extended Visual State Manager!

ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, "OffScreen", true);

This works because it takes a Framework Element... amongst other things. Workaround for VisualStateManager.GoToState not working on Window

DavidA
+1 Its best that the actual answer appear first ;)
AnthonyWJones