按钮背景透明未在WPF

时间:2015-05-13 11:33:27

标签: c# wpf

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,
                    };

图像发生了变化,但在鼠标中,背景以蓝色突出显示

2 个答案:

答案 0 :(得分:0)

更新您的样式以在MouseOver上触发背景:

<Style.Triggers>
    <Trigger Property='IsMouseOver' Value='True'>
        <Setter Property='Background' Value='White' />
    </Trigger>
</Style.Triggers>

答案 1 :(得分:0)

试试这个

 public partial class YourContext: DbContext
 {
     static YourContext()
     {
         Database.SetInitializer<YourContext>(new CreateDatabaseIfNotExists<YourContext>());
     }
 }

更多信息请参阅此网站

How do you change Background for a Button MouseOver in WPF?

Transparent button background in WPF using style