Hi guys,
May be someone knows why I can't change button's background using style trigger in IsPressed Property.
Appreciate your help.
Irina
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<Button Background="AliceBlue">Click me!</Button>
</StackPanel>
</Window>

Button Style Trigger - IsPressed Property
Balasubramaniam K
Thanks for answering but it does not change color anyway even if
<Setter Property="Background" Value="Red"/> is the only place you change the background
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="AliceBlue"></Setter>
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<Button>Click me!</Button>
</StackPanel>
</Window>
ABinBoston
Mibe
Try this instead:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<Button Background="Black">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Trigger>
</Style>
</Button.Style>
Click me!
</Button>
</StackPanel>
</Window>
HTH
Bye
taotor
http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/1fbada8e-4867-4ed1-8d97-62c07dad7ebc.asp
There is a good explanation regarding your sample in the "Dependency Properties Might be "Set" in Multiple Places" section.
So, in order to make the sample work, you should set the background to AliceBlue in a Style Setter.
Sun - By - Night
aak165842
fwpi
I've used the same code but it doesn't work....
My button are colorized in AliceBlue (normal) but they never change to Red.
I'm using Windows XP SP2 and the Feb 2006 CTP
Chernichkin Stanislav