Answer the question
In order to leave comments, you need to log in
How to change color when hovering over a control?
I tried that, but it doesn't work.
<Window.Resources>
<ControlTemplate TargetType="Button" x:Key="btTemp">
<Border x:Name="ButtonBorders" Background="{TemplateBinding Background}" BorderThickness="0" CornerRadius="5" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
<ContentControl Foreground="{TemplateBinding Foreground}" Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonBorders" Property="Background" Value="LightSeaGreen"/>
<Setter Property="Control.Foreground" Value="DarkOliveGreen"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid Background="#FF6A6A6A">
<Button Template="{StaticResource btTemp}" Content="Button" HorizontalAlignment="Left" Margin="268,214,0,0" VerticalAlignment="Top" Width="174" Height="67" FontSize="22" FontFamily="Segoe UI Black" Background="#FF785A5A" Foreground="White"/>
</Grid>
Answer the question
In order to leave comments, you need to log in
This is how it works:
<ControlTemplate x:Key="TestButtonTemplate" TargetType="Button">
<Border Background="{TemplateBinding Background}"
BorderThickness="0"
CornerRadius="5"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<ContentControl Foreground="{TemplateBinding Foreground}"
Content="{TemplateBinding Content}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question