The image shows that the menu point is blue and white, but you need to make it the same as the bottom one.

This changes the style only menu without selection. But when you highlight the color white-blue. enter image description here

<TreeView Background="#FF222222" 

But when the TreeView is defocused, the background color becomes white. How to change?

enter image description here

 <Window.Resources> <!-- Стиль для ListBox c типами документов --> <Style x:Key="SimpleListBoxItem" TargetType="ListBoxItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border Name="Border" Padding="2" SnapsToDevicePixels="true"> <ContentPresenter/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter TargetName="Border" Property="Background" Value="Blue"/> <Setter Property="Foreground" Value="White"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- List Item Hover --> <LinearGradientBrush x:Key="MouseOverFocusStyle" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStop Color="#FF013B73" Offset="0.501"/> <GradientStop Color="#FF091F34"/> <GradientStop Color="#FF014A8F" Offset="0.5"/> <GradientStop Color="#FF003363" Offset="1"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <!-- List Item Selected --> <LinearGradientBrush x:Key="LostFocusStyle" EndPoint="0.5,1" StartPoint="0.5,0"> <LinearGradientBrush.RelativeTransform> <TransformGroup> <ScaleTransform CenterX="0.5" CenterY="0.5"/> <SkewTransform CenterX="0.5" CenterY="0.5"/> <RotateTransform CenterX="0.5" CenterY="0.5"/> <TranslateTransform/> </TransformGroup> </LinearGradientBrush.RelativeTransform> <GradientStop Color="#FF091F34" Offset="1"/> <GradientStop Color="#FF002F5C" Offset="0.4"/> </LinearGradientBrush> <Style x:Key="WindowStyle" TargetType="Window"> <Setter Property="Background" Value="Black" /> </Style> <!--<Style x:Key="ButtonStyle" TargetType="Button"> <Setter Property="Background" Value="White" /> <Setter Property="Foreground" Value="Red" /> <Setter Property="BorderBrush" Value="Gray" /> </Style>--> <local:LevelToImageConverter x:Key="LevelToImageConverter"/> </Window.Resources> 

.

 <MenuItem Header="Tree"> <MenuItem Header="New Notes" Click="NewNotes" Foreground="#FFFFFFFF" Background="#FF222222" 

.

  <Style TargetType="{x:Type TreeViewItem}"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF000000"/> </Style.Resources> <Setter Property="Foreground" Value="White" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True" > <Setter Property="Foreground" Value="Silver"/> <!--<Setter Property="Background" Value="Black"/>--> <Setter Property="FontWeight" Value="Normal"/> </Trigger> <Trigger Property="IsSelected" Value="False" > <!--<Setter Property="Background" Value="#FF222222"/>--> <Setter Property="FontWeight" Value="Normal"/> </Trigger> <!--<Trigger Property="Unfocused" Value="False" > <Setter Property="Background" Value="#FF222222"/> <Setter Property="FontWeight" Value="Normal"/> </Trigger>--> </Style.Triggers> </Style> 

None of this changed the style.

 <Window x:Class="testmenu.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:testmenu" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Menu DockPanel.Dock="Top" MinHeight="25"> <Menu.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuColorKey}" Color="Green"/> </Menu.Resources> <MenuItem Header="Add"/> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuHighlightBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuHighlightColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuTextBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.MenuTextColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.ScrollBarColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowFrameBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowFrameColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowTextBrushKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> <MenuItem Header="File"> <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.WindowTextColorKey}" Color="Green"/> </MenuItem.Resources> <MenuItem Header="Add"/> <MenuItem Header="Add"/> </MenuItem> </Menu> </Window> 
  • 2
    The essence of the question is not quite clear, please post a whole code, it is even better to add images to the question. - Arthur Edgarov
  • Add the full style code as well. standard treeview without setting a style looks completely different - user2455111

2 answers 2

To highlight the active menu items, you can use the following code:

 <Menu x:Name="TopMainMenu"> <Menu.Resources> <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}"> <Border Name="Border"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut" /> <ColumnDefinition Width="13" /> </Grid.ColumnDefinitions> <ContentPresenter Name="Icon" Margin="6,0,6,0" VerticalAlignment="Center" ContentSource="Icon" /> <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header" RecognizesAccessKey="True" /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsHighlighted" Value="true"> <Setter TargetName="Border" Property="Background" Value="Yellow" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="Border" Property="Background" Value="Blue" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Menu.Resources> 
     <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Green"/> 

    You need to set this property for the TreeView. It sets the color for the element you need for the inactive state.

    As a result, your style should look like this.

     <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF000000"/> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#FF000000"/> </Style.Resources> <Setter Property="Foreground" Value="White" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True" > <Setter Property="Foreground" Value="Silver"/> <Setter Property="FontWeight" Value="Normal"/> </Trigger> <Trigger Property="IsSelected" Value="False" > <Setter Property="FontWeight" Value="Normal"/> </Trigger> </Style.Triggers> </Style> </TreeView.ItemContainerStyle> 
    • For treeview works. And for the menu - not working. <MenuItem.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Green"/> </MenuItem.Resources> - codename0082016
    • Select the properties in the list on the left. Must be a suitable msdn.microsoft.com/en-us/library/… - user2455111
    • No property works - codename0082016
    • I understand you need to highlight the MenuItem? look at stackoverflow.com/questions/8790745/… here - user2455111