这是项目中我的按钮的代码,我的要求是我想在按钮文本“附加批准”之前添加一些图像(c:\ 1.jpg),并且在单击按钮之后按钮名称被更改更改后“批准”我想添加另一个图像(c:\ 2.jpg)
<Button ToolTip="Attach Approval"
Height="25" Margin="5,10,5,10">
<Button.Style>
<Style TargetType="{x:Type Button}">
<!-- Default Content value -->
<Setter Property="Command" Value="{Binding AddAttachmentCommand}"/>
<Setter Property="Content" Value="Attach Approval">
</Setter>
<!-- Triggered values -->
<Style.Triggers>
<DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
<Setter Property="Content" Value="Appprove"/>
<Setter Property="Command" Value="{Binding ApproveTemplateCommand}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsAttachmentAvailable}" Value="False">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
答案 0 :(得分:0)
这需要使用显式样式值定义。例如:
<Style TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Image Source="YourImagePath.jpg" />
<TextBlock Text="Attach Approval" />
</StackPanel>
</Setter.Value>
</Setter>
</Style>
您可以将Content
属性设置为您喜欢的任何容器,并抛出您需要的任何元素。