【发布时间】:2015-07-24 16:01:11
【问题描述】:
WPF:我有一个按钮,图像是在 c# 后面的代码中设置的
btn.Content = new Image
{
Source = new BitmapImage(new Uri(MasterVariables.applicationPath + "Normal.png")),
Stretch = Stretch.Fill,
};
现在的问题是,当按钮进入按钮时,背景颜色设置为蓝色,但我在 mouse_enter 事件中更改了图像
btn.BorderThickness = new Thickness(0);
btn.Style = (Style)FindResource(ToolBar.ButtonStyleKey);
btn.Background = Brushes.White; btn.BorderBrush = Brushes.Transparent;
btn.Content = new Image
{
Source = new BitmapImage(new Uri(MasterVariables.applicationPath + "Hover.png")),
Stretch = Stretch.Fill,
};
图像发生了变化,但是当鼠标移到背景上时,背景会以蓝色突出显示
【问题讨论】:
-
处理适当的事件然后更改属性,但最好的方法是从 xaml