VisualState Inheritance in Silverlight

I am writing a control that inherits from RadioButton and does nothing more impressive than displaying the image and hiding the default circle.

One thing I couldn’t find out about is that I need to VisualStates all VisualStates again in my ControlTemplate, or can I just place them as an empty element and are they inherited?

My XAML is below, the original RadioButton is on MSDN .

 <Style TargetType="local:ImageRadioButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:ImageRadioButton"> <Grid> <vsm:VisualStateManager.VisualStateGroups> <vsm:VisualStateGroup x:Name="CommonStates"> <vsm:VisualState x:Name="Normal"/> <vsm:VisualState x:Name="MouseOver"> <Storyboard/> <!-- mouseover --> </vsm:VisualState> <vsm:VisualState x:Name="Pressed" /> <vsm:VisualState x:Name="Disabled"/> <!-- TODO --> </vsm:VisualStateGroup> <vsm:VisualStateGroup x:Name="CheckStates"> <vsm:VisualState x:Name="Checked"> <Storyboard/> <!-- checked --> </vsm:VisualState> <vsm:VisualState x:Name="Unchecked"/> </vsm:VisualStateGroup> <vsm:VisualStateGroup x:Name="FocusStates"> <vsm:VisualState x:Name="Focused" /> <vsm:VisualState x:Name="Unfocused" /> </vsm:VisualStateGroup> <vsm:VisualStateGroup x:Name="ValidationStates"> <vsm:VisualState x:Name="Valid"/> <vsm:VisualState x:Name="InvalidUnfocused" /> <vsm:VisualState x:Name="InvalidFocused" /> </vsm:VisualStateGroup> </vsm:VisualStateManager.VisualStateGroups> <ContentPresenter/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 
+4
source share
2 answers

You do not have to override visual states, but they will also not be "inherited." If you specify a new DefaultStyleKey for your new control, you will not get anything from the original style.

If you want your new control to change its appearance to represent its current state, for example, whether it has focus, or its selection, you will need to include the appropriate set of VisualStateGroups . Then include the appropriate animations in your VisualState elements to change the new version of the button user interface.

+2
source

All or nothing. If you replace the template, you must provide it all, including visual states. Blend makes editing a copy of the default template easy.

+3
source

Source: https://habr.com/ru/post/1309539/


All Articles