要是想实现,点击后换成另外一个图片不变,还应该怎么办?
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ControlTemplate x:Key="IconButton" TargetType="{x:Type Button}">
<Grid >
<Image x:Name="myimage" Source="c:\users\candy\documents\visual studio 2010\Projects\WpfApplication2\WpfApplication2\Images\1.jpg" Height="27" Width="65" />
<Border>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Border>
</Grid>
<ControlTemplate.Triggers >
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="myimage" Property="Source" Value="c:\users\candy\documents\visual studio 2010\Projects\WpfApplication2\WpfApplication2\Images\2.jpg" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Button Width="50" Height="30" Template="{StaticResource IconButton}" Margin="15" HorizontalAlignment="Left" x:Name="Start" ToolTip="Start measurement">
</Button>
</Window>
------解决方案--------------------
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=S}" Value="1">
<Setter TargetName="rectangle" Property="Fill">
<Setter.Value>
<ImageBrush ImageSource="c:\users\candy\documents\visual studio 2010\Projects\WpfApplication2\WpfApplication2\Images\2.jpg" ></ImageBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</ControlTemplate.Triggers>
用类似于这样的后台绑定一个数据的方法