wpf如何给button设置图片触发器
最近做一个wpf的页面,需要对button重新进行定义,我就做了如下定义
<ImageBrush ImageSource="f:\cc.png" x:Key="ButtonNormalImage"/>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalImage}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
x:Name="btnBorder"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="f:\bb.jpg"></ImageBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
针对一个单个的button这样就ok了,但是如果在button里面再自定义一个background,如下
<Button x:Name="button" Content="other" Margin="163,61,279,209" Height="50" Width="70"
Click="button_Click" Style="{DynamicResource ButtonStyle1}" Foreground="White" >
<Button.Background>
<ImageBrush ImageSource="f:\aa.jpg"></ImageBrush>
</Button.Background>
</Button>
则该按钮的触发事件就不起作用了,只能在程序样式里面自己去定义么?
如果我有10个按钮,每一个按钮的image都不一样的话,我是不是要写10个样式?
如果我需要那种在按钮上设置两个值,如img1="aa.jpg" img2="bb.jpg",然后让这两个值分别作为按钮的触发器的背景的话
是不是要写自定义控件?