我有一个样式按钮如下:
<Style x:Key="btnDefaultOperationImage" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="brdMenu"
BorderThickness="0"
Padding="4,2"
BorderBrush="White"
Background="#20000000">
<StackPanel>
<ContentPresenter x:Name="ButtonContentPresenter" VerticalAlignment="Center" HorizontalAlignment="Center">
<ContentPresenter.Resources>
<Style TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Center" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/Images/Icons/CourtHearing.png" />
<Style.Triggers>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我想在许多按钮上使用这种样式,但是每个按钮都会根据其名称具有不同的图像,例如:
按钮Name="btnCases"的ImageSource="..\..\Cases.png"
按钮Name="btnActors"的ImageSource="..\..\Actors.png"
我想知道是否可以DataTrigger用来解决这个问题,我试过了
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}, Path=Name}" Value="btnCases">
但它不起作用。
相关分类