这是我目前用来为可重复使用的简单后退按钮设置动画的代码,问题是我还需要另一个具有相同属性的按钮,但可以根据将要显示的屏幕指定文本用过的。
为了显示效果和文本,我必须添加什么?(我所有添加文本的尝试只是使按钮完全消失。)
<UserControl x:Class="SantaBarbara.Resources.BackButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
>
<Button Width="116" Height="119" Canvas.Top="57" BorderThickness="0" BorderBrush="Transparent">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Resources>
<SolidColorBrush x:Key="BackgroundBrush" Color="#990050" Opacity="0.50" />
</Style.Resources>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ControlTemplate.Resources>
<Storyboard x:Key="MouseOverAnimation">
<DoubleAnimation Duration="0:0:0.5" To="0.9" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Opacity)" Storyboard.TargetName="Border" />
</Storyboard>
<Storyboard x:Key="MouseOutAnimation">
<DoubleAnimation Duration="0:0:0.5" To="0.5" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Opacity)" Storyboard.TargetName="Border" />
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" >
<ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource MouseOverAnimation}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource MouseOutAnimation}" />
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</UserControl>