如何在按下按钮时保持按钮的背景相同?
以下是来自应用程序的代码片段:我正在使用 WPF 和 XAML 进行开发。我想做的是让按钮的背景在用户单击时与用户未单击时保持相同的颜色。
注意:按钮中有一个图像。
<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>`
我的问题是,为什么这段代码不能产生我想要的结果?
Possible Duplicate:
WPF Button isPressed and isEnabled problem
Here is a snippet of code from an application that I am developing using WPF and XAML. What I am trying to do is get the button's background to stay the same color when it is clicked on by the user as it is when it is not clicked on by the user.
Note: There is an image in the button.
<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>`
My question is, why doesn't this code produce the results that I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 wpf 中,按钮有一个覆盖样式值的默认模板。有关如何使用模板更改值的示例,请参阅此处。
In wpf buttons have a default template that overrides style values. See here for an example of how to change the value using a template.