Note that there are some explanatory texts on larger screens.

plurals
  1. POVisualStateManager -- showing mouseover state when control is focused
    primarykey
    data
    text
    <p>I am creating a WPF button using Windows 8 styling (formerly metro).</p> <p>I would like the focused state of the button to show with a solid background. When the mouse is over the control, I would like th background to darken slightly to create the visual cue that the button can be clicked.</p> <p>Unfortunately, the XAML I've written below does not work. The focused state shows correctly, but when the mouse is over the control, the background does not darken as I would like it to.</p> <pre><code>&lt;Color x:Key="DoxCycleGreen"&gt; #FF8DC63F &lt;/Color&gt; &lt;!-- Soft Interface : DoxCycle Green --&gt; &lt;Color x:Key="DoxCycleGreenSoft"&gt; #FFC0DC8F &lt;/Color&gt; &lt;Style x:Key="MetroButton" TargetType="{x:Type Button}"&gt; &lt;Setter Property="FocusVisualStyle" Value="{x:Null}"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="Button"&gt; &lt;Border Name="RootElement"&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup Name="CommonStates"&gt; &lt;VisualState Name="Normal" /&gt; &lt;VisualState Name="MouseOver"&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" To="{StaticResource DoxCycleGreen}" Duration="0:0:0.150" /&gt; &lt;ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="White" Duration="0:0:0.150" /&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState Name="Focused"&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" To="{StaticResource DoxCycleGreenSoft}" Duration="0:0:0.150" /&gt; &lt;ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="White" Duration="0:0:0.150" /&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState Name="Pressed"&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName="BackgroundColor" Storyboard.TargetProperty="Color" To="Transparent" Duration="0:0:0.150" /&gt; &lt;ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="{StaticResource DoxCycleGreen}" Duration="0:0:0.150" /&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;VisualState Name="Disabled"&gt; &lt;Storyboard&gt; &lt;ColorAnimation Storyboard.TargetName="BorderColor" Storyboard.TargetProperty="Color" To="DarkGray" Duration="0:0:0.1" /&gt; &lt;ColorAnimation Storyboard.TargetName="FontColor" Storyboard.TargetProperty="Color" To="DarkGray" Duration="0:0:0.1" /&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;Grid Background="Transparent" &gt; &lt;Border BorderThickness="1,1,1,1" Padding="2"&gt; &lt;Border.BorderBrush&gt; &lt;SolidColorBrush x:Name="BorderColor" Color="{StaticResource DoxCycleGreen}"/&gt; &lt;/Border.BorderBrush&gt; &lt;Border.Background&gt; &lt;SolidColorBrush x:Name="BackgroundColor" Color="White"/&gt; &lt;/Border.Background&gt; &lt;ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Content"&gt; &lt;TextBlock.Foreground&gt; &lt;SolidColorBrush x:Name="FontColor" Color="{StaticResource DoxCycleGreen}"/&gt; &lt;/TextBlock.Foreground&gt; &lt;/ContentPresenter&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </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.
 

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