Visual State Manager on Custom Control
Asked Answered
H

2

5

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?

Handcar answered 13/1, 2010 at 9:38 Comment(1)
Browsing through the behaviour, it takes a framework element rather than a control. This works.Handcar
H
7

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

Handcar answered 13/1, 2010 at 11:39 Comment(0)
R
1

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
Remex answered 13/1, 2010 at 10:9 Comment(1)
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.Handcar

© 2022 - 2024 — McMap. All rights reserved.