【发布时间】:2026-01-30 12:15:02
【问题描述】:
这是我正在使用 WPF 和 XAML 开发的应用程序的代码的 sn-p。我想要做的是让按钮的背景在用户单击时保持与用户未单击时相同的颜色。
注意:按钮中有图片。
<Button Name="Button1" Background="#3852A4" Grid.Column="0" Grid.Row="0" Width="35" Height="35" HorizontalAlignment="Left" VerticalAlignment="Top" Click="swapGd1andGd2">
<Button.Style>
<Style>
<Style.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Button.Background" Value="#3852A4" />
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Image Source="Images/112_DownArrowShort_Grey_24x24_72.png" Width="24" Height="24" Stretch="Fill"></Image>
</Button>`
我的问题是,为什么这段代码没有产生我想要的结果?
【问题讨论】:
-
如果你能告诉我如何更好地格式化这段代码,请告诉我。对*来说相当新。
-
阅读this。
-
同意。可能合并我的答案?另一个没有提到为什么只设置样式不起作用。
标签: wpf xaml button background click