Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Menu displays to the left of the window

Tags:

wpf

xaml

menu

I have a simple Menu in a DockPanel. Here is the XAML:

<Window x:Class="WpfApplication1.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">
<DockPanel>
    <Menu DockPanel.Dock="Top">
        <MenuItem Name="file" Header="_File">
            <MenuItem Name="exitMenuItem" Header="E_xit"/>
        </MenuItem>
    </Menu>
    <Grid>
    </Grid>
</DockPanel>

Why does the Menu drop down to the left instead of the right of the window border like most applications?

screenshot of Window

like image 450
Nate Avatar asked Jan 07 '11 22:01

Nate


2 Answers

It appears that you have a tablet input device. Follow the instructions in this link to change the handedness in your Tablet PC Settings:

  • menus appear to the left of my cursor
like image 126
Rick Sladkey Avatar answered Sep 28 '22 23:09

Rick Sladkey


A fix that worked for me was:

        var ifLeft = SystemParameters.MenuDropAlignment;
        if (ifLeft)
        {
            // change to false
            var t = typeof(SystemParameters);
            var field = t.GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
            field.SetValue(null, false);
            ifLeft = SystemParameters.MenuDropAlignment;
        }

Credit: https://www.telerik.com/forums/popup-is-opening-to-outside-window-in-splitbutton

like image 23
MikeP. Avatar answered Sep 28 '22 22:09

MikeP.