<ControlTemplate x:Key="UserButton" TargetType="{x:Type Button}">
<Grid> <Image x:Name="defaultimage" HorizontalAlignment="Stretch" Width="210" Height="55" Stretch="None" Source="b4.png"/> <Image x:Name="forcusimage" HorizontalAlignment="Stretch" Width="210" Height="55" Stretch="None" Panel.ZIndex="10" Source="b5.png" Visibility="Hidden"/> <TextBlock x:Name="text" Margin="0" TextWrapping="Wrap" Text="click button" HorizontalAlignment="Center" Panel.ZIndex="100"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"></Trigger>
</ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="UserButton1" TargetType="{x:Type Button}"> <Grid> <Image Name="img" Source="/b4.png"/> <!--TextBlock Name="text" Text="文字" HorizontalAlignment="Center" VerticalAlignment="Center"/--> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="img" Property="Source" Value="/b5.png"> </Setter> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="img" Property="Source" Value="/b6.png"> </Setter> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="img" Storyboard.TargetProperty="Width" From="150" To="200" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="img" Storyboard.TargetProperty="Width" From="200" To="150" Duration="0:0:0.1" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>//调用
<Button Content="文字" Width="150" Tag="zoomout" ToolTip="放大" Template="{StaticResource UserButton1}" />