I'm trying to do my own button style. I want to the MouseEnter
and the MouseLeave
event to use the color chosen for BorderBrush
and Background
respectively.
My style code is:
<Style x:Key="RoundButton" TargetType="Button">
<Setter Property="Padding" Value="5"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Margin="-1"
CornerRadius="3"
Background="{TemplateBinding Background}"
BorderThickness="0.7"
BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter
Margin="-1"
x:Name="MyContentPresenter"
Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="{Binding (CHOSEN BORDER BRUSH)}" Duration="0:0:0.1" Storyboard.TargetProperty="Background.Color"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="{Binding (CHOSEN BACKGROUND BURSH)}" Duration="0:0:0.1" Storyboard.TargetProperty="Background.Color"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
My usage is:
<Button Grid.Row="1"
Style="{StaticResource RoundButton}"
Height="30"
HorizontalAlignment="Right"
Margin="10"
Background="Green"
BorderBrush="ForestGreen">
I would like to do that using only XAML, without any converters, if possible.