Reputation: 771
Basically this is a button existing out of rectangle and several textblocks. The rectangle Fill
is representing the background of my button. How can i change this when the button is pressed?
The background also has to stay in that color after pressing the button. This basically shows the user visually what buttons have been pressed and what not.
Part of my Style:
<Style x:Key="ButtonStyleReg" TargetType="{x:Type myClasses:RegButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="regButton">
<Rectangle Name="rectangleBtn" Fill="#FF89959A" Height="Auto" RadiusY="15" RadiusX="15" Stroke="White" Width="Auto"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsPressed" Value="True" >
<Setter TargetName="rectangleBtn" Property="Fill" Value="Blue" />
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="10.667"/>
Upvotes: 0
Views: 1512
Reputation: 4167
You must address the correct element, try giving the rectangle a name and pointing the setter to it by name reference:
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="regButton">
<Rectangle Fill="#FF89959A"
x:Name="rect"
Height="Auto"
RadiusY="15"
RadiusX="15"
Stroke="White"
Width="Auto" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused"
Value="True" />
<Trigger Property="IsDefaulted"
Value="True" />
<Trigger Property="IsPressed"
Value="True">
<Setter Property="Background"
TargetName="rect"
Value="Blue" />
<!--??-->
</Trigger>
<Trigger Property="IsEnabled"
Value="False" />
</ControlTemplate.Triggers>
</ControlTemplate>
Upvotes: 2