<Style x:Key="SwitchImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Null}">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"/>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="true">
<!--IsPressed-->
<Setter TargetName="Border" Property="Background" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
引用列子:
<Button Canvas.Left="0" Canvas.Top="0" Height="45" x:Name="button1" Width="180" Style="{StaticResource SwitchImageButtonStyle}" Command="{Binding RecentlyAddCmd}">
<Button.Foreground>
<ImageBrush ImageSource="/MediaCenter;component/Images/Common_Shared/BottomBar/btns_recently_added_activated.png"></ImageBrush>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="/MediaCenter;component/Images/Common_Shared/BottomBar/btns_recently_added.png"/>
</Button.Background>
</Button>