Menu item WPF custom template

Hi, I create a custom menu with menu items. I manage change the background of the menu item but still it is surrounded of some grey container. I don't find in the template for menu item nothing that can customaze this container.
Do you have any suggestions?
Screen-Shot-03-06-18-at-01.55-PM.PNG
LVL 1
mastiSoftAsked:
Who is Participating?
 
MishaProgrammerCommented:
If you want to hide "container" of menu, you should use "Popup"

Try this:

<Window x:Class="TestMenu.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
            <Border Name="Border" >
                <Grid>
                    <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
                    <Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
                        <Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="Transparent">
                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                        </Border>
                    </Popup>
                </Grid>
            </Border>
        </ControlTemplate>
    </Window.Resources>
    
    <Grid>
        <Menu Height="25" VerticalAlignment="Top">
            <MenuItem Header="File"  >
                <MenuItem Header="New" Background="Red" ></MenuItem>
                <MenuItem Header="Open" ></MenuItem>
                <MenuItem Header="Save" ></MenuItem>
            </MenuItem>
        </Menu>
    </Grid>
</Window>

Open in new window

0
 
Juan OcasioApplication DeveloperCommented:
Did you check the XAML for any margins or padding?
0
 
mastiSoftAuthor Commented:
Yes I did but there is only infromation for Icon, text and stuff like that.
0
 
Juan OcasioApplication DeveloperCommented:
0
 
mastiSoftAuthor Commented:
Thank you but it this is not resolved the problem I have.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.