我在这里有我的按钮,它有一些动画自定义样式,但我有 6 个,我讨厌看整个 xaml,每个按钮有 41 行
<Button Width="250" Height="120" HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="btnShutdown" IsDefault="False" BorderThickness="2">
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Height="120" Width="250" Background="Red">
<Image Grid.ColumnSpan="2" Grid.RowSpan="2" Height="120" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Fill" Width="120" Source="/SystemPowerShortcuts;component/image_res/shutdown.png" />
<TextBlock Height="19" HorizontalAlignment="Left" Margin="14,95,0,6" Text="Shutdown" VerticalAlignment="Center" FontSize="12" Width="66" Foreground="White" FontWeight="Normal" />
</Grid>
<Button.RenderTransform>
<RotateTransform x:Name="btnShutdown_Transform" Angle="0" />
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="btnShutdown_Transform"
Storyboard.TargetProperty="Angle"
To="-1" Duration="0:0:0.1" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="btnShutdown_Transform"
Storyboard.TargetProperty="Angle"
To="-5" Duration="0:0:0.1" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Button.MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="btnShutdown_Transform"
Storyboard.TargetProperty="Angle"
To="0" Duration="0:0:0.3" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
你如何将它转换为资源,所以我没有很长的 xaml 代码?
按钮具有自定义图像和文本,但具有相同的动画