Anja Simonsen

Anja Simonsen

  • NA
  • 41
  • 15.5k

Styles with Trigger on IsMouseOver still shows the winfows blue color

Mar 8 2021 4:02 PM
Right now I'm trying to use styles in my very new wpf solution.
 
I have problems with the Trigger IsMouseOver background color. Even when using another background color it still shows Windows blue on mouse over. Do I have to set another property for the mouse over blue color?
 
Can anyone tell me, why I can make the style Bold but not cann't change the windows normal blue color on mouseover a button?
 
I have attached the solution
 
But here is the code first my app.xaml file
  1. <Application x:Class="AnsiBug.App"    
  2.              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
  4.              xmlns:local="clr-namespace:AnsiBug"    
  5.              StartupUri="MainWindow.xaml">    
  6.     <Application.Resources>    
  7.         <!--#region Buttons -->            
  8.         <!--Almindelige knapper-->    
  9.         <Style TargetType="Button">    
  10.             <Setter Property="Background" Value="#005b7f"/>    
  11.             <Setter Property="Foreground" Value="White" />    
  12.             <Setter Property="FontFamily" Value="Verdana" />    
  13.             <Setter Property="FontSize" Value="12" />    
  14.             <Setter Property="Margin" Value="3" />    
  15.             <Setter Property="Padding" Value="5 5 5 5" />    
  16.         </Style>    
  17.             
  18.         <!--Top Menu knapper-->    
  19.         <Style TargetType="Button" x:Key="TopMenuButton">    
  20.             <Setter Property="Background" Value="White"/>    
  21.             <Setter Property="Foreground" Value="Black" />    
  22.             <Setter Property="FontFamily" Value="Verdana" />    
  23.             <Setter Property="FontSize" Value="12" />                
  24.             <Setter Property="Width" Value="120" />    
  25.             <Setter Property="HorizontalAlignment" Value="Left" />    
  26.             <Setter Property="HorizontalContentAlignment" Value="Left" />    
  27.             <Setter Property="BorderThickness" Value="0" />    
  28.             <Setter Property="BorderBrush" Value="Transparent" />    
  29.             <Setter Property="Padding" Value="5 0 2 2" />    
  30.             <Style.Triggers>    
  31.                 <Trigger Property="IsMouseOver" Value="True">    
  32.                     <Setter Property="Background" Value="White" />    
  33.                     <Setter Property="FontWeight" Value="Bold" />    
  34.                 </Trigger>    
  35.             </Style.Triggers>    
  36.         </Style>    
  37.     
  38.         <!--Top SubMenu knapper-->    
  39.         <Style TargetType="Button" x:Key="TopSubMenuButton">    
  40.             <Setter Property="Background" Value="#005b7f"/>    
  41.             <Setter Property="Foreground" Value="White" />    
  42.             <Setter Property="FontFamily" Value="Verdana" />    
  43.             <Setter Property="FontSize" Value="12" />    
  44.             <Setter Property="HorizontalAlignment" Value="Left" />    
  45.             <Setter Property="Width" Value="120" />    
  46.             <Setter Property="HorizontalContentAlignment" Value="Left" />    
  47.             <Setter Property="BorderThickness" Value="0" />    
  48.             <Setter Property="BorderBrush" Value="Transparent" />    
  49.             <Setter Property="Padding" Value="5 2 2 0" />    
  50.             <Style.Triggers>    
  51.                 <Trigger Property="IsMouseOver" Value="True">    
  52.                     <Setter Property="Background" Value="#005b7f" />    
  53.                     <Setter Property="FontWeight" Value="Bold" />    
  54.                 </Trigger>    
  55.             </Style.Triggers>    
  56.         </Style>    
  57.         <!--#endregion-->    
  58.     </Application.Resources>    
  59. </Application>  
And here is my
 
My MainWindow (the two first images are logos You can put every image you want. The Divider image is included in the solution.
  1. <Window xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Name="AnsiBug"  x:Class="AnsiBug.MainWindow"    
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
  4.         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    
  5.         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
  6.         xmlns:local="clr-namespace:AnsiBug"    
  7.         mc:Ignorable="d"    
  8.         Title="MainWindow" Height="800" Width="1200" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStartupLocation="CenterScreen">    
  9.     <Window.Resources>    
  10.         <!--Base Button Style-->    
  11.     </Window.Resources>    
  12.     <StackPanel>    
  13.         <Border BorderBrush="Black" BorderThickness="2">    
  14.         <Grid Margin="5" ShowGridLines="True">    
  15.             <Grid.ColumnDefinitions>    
  16.                 <ColumnDefinition Width="250"/>    
  17.                 <ColumnDefinition Width="*"/>    
  18.                 <ColumnDefinition Width="250"/>    
  19.             </Grid.ColumnDefinitions>    
  20.                 <Image Source="/Images/Logo/ANSI.gif" HorizontalAlignment="Left" Width="200"  Height="80" Grid.Column="0" Margin="0,0,111,125" />    
  21.                 <Image Source="/Images/Logo/logoBug.gif" HorizontalAlignment="Right" Width="150" Height="80" Grid.Column="2" Margin="158,0,0,149" />    
  22.                 <Grid Grid.Column="1">    
  23.                     <Grid>    
  24.                         <Grid.ColumnDefinitions>    
  25.                             <ColumnDefinition Width="*" />    
  26.                             <ColumnDefinition Width="*" />    
  27.                             <ColumnDefinition Width="*" />    
  28.                             <ColumnDefinition Width="*" />    
  29.                             <ColumnDefinition Width="*" />    
  30.                             <ColumnDefinition Width="*" />                                
  31.                         </Grid.ColumnDefinitions>    
  32.                         <Grid.RowDefinitions>    
  33.                             <RowDefinition Height="*" />    
  34.                         </Grid.RowDefinitions>    
  35.                         <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0">    
  36.                             <Button x:Name="BtnProjects" Content="Projekter" Style="{StaticResource TopMenuButton}" />    
  37.                             <Image Source="/Images/TopDivider.jpg" />    
  38.                             <StackPanel x:Name="ProjectsSubMenu">    
  39.                                 <Button x:Name="BtnDashBoard" Content="Dashboard" Style="{StaticResource TopSubMenuButton}" />    
  40.                                 <Button x:Name="BtnNewBug" Content="Ny fejl" Style="{StaticResource TopSubMenuButton}" />    
  41.                             </StackPanel>    
  42.     
  43.                         </StackPanel>    
  44.                     </Grid>    
  45.                         
  46.                     <!--Række 0 Projekter-->    
  47.                     <!--Række 1-->    
  48.                     <!--Række 2-->    
  49.                     <!--Række 3-->    
  50.                     <!--Række 4-->    
  51.                     <!--Række 5-->    
  52.                 </Grid>    
  53.             </Grid>    
  54.         </Border>    
  55.         <Grid Margin="5">    
  56.             <Grid.ColumnDefinitions>    
  57.                 <ColumnDefinition Width="*" />    
  58.             </Grid.ColumnDefinitions>    
  59.             <Grid.RowDefinitions>    
  60.                 <RowDefinition Height="*" />    
  61.             </Grid.RowDefinitions>    
  62.             <TextBlock Text="Her kommer anden række" />    
  63.         </Grid>    
  64.     </StackPanel>    
  65. </Window>  
Best regards,
Simsen :-)

Attachment: AnsiBugSolution.zip

Answers (2)