首页 > 解决方案 > IsMouserOver 上带有触发器的样式仍显示窗口蓝色

问题描述

现在我正在尝试在我非常新的 wpf 解决方案中使用样式。

我对 Trigger IsMouseOver 背景颜色有疑问。即使使用其他背景颜色,鼠标悬停时仍会显示 Windows 蓝色。我是否必须为鼠标在蓝色上设置另一个属性?

我的 app.xaml

<Application x:Class="AnsiBug.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:AnsiBug"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <!--#region Buttons -->        
        <!--Almindelige knapper-->
        <Style TargetType="Button">
            <Setter Property="Background" Value="#005b7f"/>
            <Setter Property="Foreground" Value="White" />
            <Setter Property="FontFamily" Value="Verdana" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Margin" Value="3" />
            <Setter Property="Padding" Value="5 5 5 5" />
        </Style>
        
        <!--Top Menu knapper-->
        <Style TargetType="Button" x:Key="TopMenuButton">
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="FontFamily" Value="Verdana" />
            <Setter Property="FontSize" Value="12" />            
            <Setter Property="Width" Value="120" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="Padding" Value="5 0 2 2" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="White" />
                    <Setter Property="FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <!--Top SubMenu knapper-->
        <Style TargetType="Button" x:Key="TopSubMenuButton">
            <Setter Property="Background" Value="#005b7f"/>
            <Setter Property="Foreground" Value="White" />
            <Setter Property="FontFamily" Value="Verdana" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Width" Value="120" />
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="Padding" Value="5 2 2 0" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#005b7f" />
                    <Setter Property="FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <!--#endregion-->
    </Application.Resources>
</Application>

我的 MainWindow (前两个图像是徽标您可以放置​​所需的每个图像。我附上的 Divider 图像。

<Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Name="AnsiBug"  x:Class="AnsiBug.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:AnsiBug"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="1200" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <!--Base Button Style-->
    </Window.Resources>
    <StackPanel>
        <Border BorderBrush="Black" BorderThickness="2">
        <Grid Margin="5" ShowGridLines="True">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="250"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="250"/>
            </Grid.ColumnDefinitions>
                <Image Source="/Images/Logo/ANSI.gif" HorizontalAlignment="Left" Width="200"  Height="80" Grid.Column="0" Margin="0,0,111,125" />
                <Image Source="/Images/Logo/logoBug.gif" HorizontalAlignment="Right" Width="150" Height="80" Grid.Column="2" Margin="158,0,0,149" />
                <Grid Grid.Column="1">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />                            
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0">
                            <Button x:Name="BtnProjects" Content="Projekter" Style="{StaticResource TopMenuButton}" />
                            <Image Source="/Images/TopDivider.jpg" />
                            <StackPanel x:Name="ProjectsSubMenu">
                                <Button x:Name="BtnDashBoard" Content="Dashboard" Style="{StaticResource TopSubMenuButton}" />
                                <Button x:Name="BtnNewBug" Content="Ny fejl" Style="{StaticResource TopSubMenuButton}" />
                            </StackPanel>

                        </StackPanel>
                    </Grid>
                    
                    <!--Række 0 Projekter-->
                    <!--Række 1-->
                    <!--Række 2-->
                    <!--Række 3-->
                    <!--Række 4-->
                    <!--Række 5-->
                </Grid>
            </Grid>
        </Border>
        <Grid Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="Her kommer anden række" />
        </Grid>
    </StackPanel>
</Window>
```[An Divider which the width is 120px and the height is 2px ][1]
    


  [1]: https://i.stack.imgur.com/IKQkf.jpg

标签: wpfstyles

解决方案


最后我想通了。我必须有一个模板来覆盖系统颜色


推荐阅读