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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With