我创建了此按钮模板
<ControlTemplate x:Key="RoundedButton" TargetType="{x:Type Button}">
<Border x:Name="buttonBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
TextBlock.Foreground="{TemplateBinding Foreground}"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}"
CornerRadius="{Binding ElementName=buttonImage, Path=RenderSize}">
<Grid>
<Image x:Name="buttonImage" Source="Images/send.png"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="buttonImage" Property="Opacity" Value="0.8"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="buttonBorder" Property="BorderThickness" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我想像其他属性一样在MainWindow.xaml中更改Image Source。 示例:我可以在MainWindow.xaml中更改Background,因为我给出了 Background =“ {TemplateBinding Background}” ,但是在Image标签中不起作用。如果您有帮助,我将不胜感激