Safi Mustafa
Safi Mustafa

Reputation: 175

Menu item background Not changing When IsSubMenu Property is triggered

I am trying to change background color of selcted menu item whose submenu is opened.If I change the width or foreground color when IsSubMenuOpen Property is true it's working, but the background color don't change. Can anyone tell me the reason?

Here is My Code:

 <UserControl x:Class="RoboHealthApplication.UserControls.LeftMenu"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="320"


                 >
        <UserControl.Resources>
            <Style TargetType="MenuItem">
                <Setter Property="Background" Value="#E4ADB0"/>
                <Setter Property="MinWidth" Value="230px"/>
                <Setter Property="MinHeight" Value="50px"/>
                <Setter Property="FontSize" Value="20px"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="#F0E0E0" />
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Background" Value="#F0E0E0" />
                    </Trigger>
                    <Trigger Property="IsSubmenuOpen" Value="true">
                        <Setter Property="Background" Value="Orange" />

                        <Setter Property="MinWidth" Value="500px" />
                        <Setter Property="Foreground" Value="Orange" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </UserControl.Resources>
        <DockPanel LastChildFill="False" Margin="0 20 0 20">
            <DockPanel LastChildFill="False" MinWidth="70px" MinHeight="300px" Background="#9A1F24">

            </DockPanel>
            <DockPanel LastChildFill="False" MinWidth="240px" MinHeight="300px" Background="#C2272D">
                <Menu MinWidth="240px" 
            MinHeight="300px"
             Foreground="#9A1F24"
            VerticalAlignment="Top"
            HorizontalAlignment="Left"
            Background="#C2272D"
           >

                    <Menu.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </Menu.ItemsPanel>

                    <MenuItem Header="Bar Code">
                    </MenuItem>

                    <MenuItem Header="Appointments">
                    </MenuItem>
                    <MenuItem Header="Pharmacy">
                    </MenuItem>
                    <MenuItem Header="Staff">
                        <MenuItem Header="Option1"/>
                        <MenuItem Header="Option2"/>
                        <Separator/>
                        <MenuItem Header="Option3"/>
                        <MenuItem Header="Option4"/>
                    </MenuItem>
                    <MenuItem Header="Doctor">
                        <MenuItem Header="Option1"/>
                        <MenuItem Header="Option2"/>
                        <Separator/>
                        <MenuItem Header="Option3"/>
                        <MenuItem Header="Option4"/>
                    </MenuItem>
                    <MenuItem Header="Patients">
                        <MenuItem Header="Option1"/>
                        <MenuItem Header="Option2"/>
                        <Separator/>
                        <MenuItem Header="Option3"/>
                        <MenuItem Header="Option4"/>
                    </MenuItem>
                </Menu>
            </DockPanel>
        </DockPanel>
    </UserControl>

Upvotes: 2

Views: 246

Answers (1)

OT_DEV
OT_DEV

Reputation: 171

You will need to override the menu control template for achieving this.You can refer this menucontroltemplate

Upvotes: 2

Related Questions