U
uncaged
I want to change a button's background for mouse-over and click. My
mouse-over trigger changes the background for a moment before it changes to
the default, and my click trigger never works. I'm running on Vista with
Aero, and I suspect that ButtonChrome is getting in my way.
<Window x:Class="CashDeskClient.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Style Test" Height="300" Width="453"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0">Button 1</Button>
<Button Grid.Column="1" Focusable="False">
<Button.Style>
<Style>
<!-- The following background works: -->
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Green" Offset="0.5" />
<GradientStop Color="Green" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- The following IsMouseOver trigger works for a moment, then the
background changes to the default for mouse-over. -->
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Red" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<!-- The following IsPressed trigger never changes the background to
yellow. Instead, I see the default pressed background. -->
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Yellow" Offset="0.5" />
<GradientStop Color="Yellow" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
Button 2
</Button>
<Button Grid.Column="2" Focusable="False">Button 3</Button>
</Grid>
</Window>
Thanks.
mouse-over trigger changes the background for a moment before it changes to
the default, and my click trigger never works. I'm running on Vista with
Aero, and I suspect that ButtonChrome is getting in my way.
<Window x:Class="CashDeskClient.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Style Test" Height="300" Width="453"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0">Button 1</Button>
<Button Grid.Column="1" Focusable="False">
<Button.Style>
<Style>
<!-- The following background works: -->
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Green" Offset="0.5" />
<GradientStop Color="Green" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- The following IsMouseOver trigger works for a moment, then the
background changes to the default for mouse-over. -->
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Red" Offset="0.5" />
<GradientStop Color="Red" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<!-- The following IsPressed trigger never changes the background to
yellow. Instead, I see the default pressed background. -->
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Button.Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="Yellow" Offset="0.5" />
<GradientStop Color="Yellow" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
Button 2
</Button>
<Button Grid.Column="2" Focusable="False">Button 3</Button>
</Grid>
</Window>
Thanks.