Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a similar problem! I had the Visual States defined within a grid in the ControlTemplate.</p> <pre><code> &lt;Style x:Key="Image3TextRowButtonStyle" TargetType="Button"&gt; &lt;Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="Button"&gt; &lt;Grid x:Name="RootGrid" Background="{StaticResource BackgroundBrush}"&gt; ... &lt;VisualStateManager.VisualStateGroups&gt; ... &lt;VisualStateGroup x:Name="ActiveStates"&gt; &lt;VisualState x:Name="Active"&gt; &lt;Storyboard&gt; &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background)" Storyboard.TargetName="RootGrid"&gt; &lt;DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackgroundActiveBrush}"/&gt; &lt;/ObjectAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState x:Name="NotActive" /&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>And the user control:</p> <pre><code>&lt;UserControl x:Class="Griesser.Presentation.ContactCenterClient.Client.Control.Image3TextRowButtonUC" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" x:Name="Image3TextRowButton"&gt; &lt;Grid&gt; &lt;Button x:Name="btn" Command="{Binding Command, ElementName=Image3TextRowButton}" Style="{StaticResource Image3TextRowButtonStyle}" /&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>In the code behind I am looking first for the RootGrid and then use GoToElementState: </p> <pre><code> private void ChangeVisualActiveState(bool useTransitions) { // Search RootGrid, because the Visual States are defined in the ControlTemplate! FrameworkElement dt = btn.Template.FindName("RootGrid", btn) as FrameworkElement; if (IsActive) { VisualStateManager.GoToElementState(dt, "Active", useTransitions); } else { VisualStateManager.GoToElementState(dt, "NotActive", useTransitions); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload