How to change orientation/location of menuitem in menubar

When I create a menu in XAML like this:

<Menu>
    <MenuItem Height="auto" Header="{x:Static str:StringResources.File}">
        <MenuItem Header="{x:Static str:StringResources.Open}"
                  InputGestureText="Ctrl+O" 
                  Command="{Binding OpenFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.Save}" 
                  InputGestureText="Ctrl+S" 
                  Command="{Binding SaveFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.SaveAs}" 
                  InputGestureText="Ctrl+Shift+S" 
                  Command="{Binding SaveAsFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.Exit}"
                  InputGestureText="Alt+F4"
                  Click="MenuItemExit_Click"
                  />
    </MenuItem>
</Menu>

The menu is folded out with the edge of the menu right-aligned to the edge of the top menu item (File in this case). This means that the menu looks like this:

                  _____________________________________________
__________________|____|File|_____________________________-|_|X|
|   | Open            Ctrl+O|                                  |
|   | Save            Ctrl+S|                                  |
|   | Save As.. Ctrl+Shift+S|                                  |
|   | Exit            Alt+F4|                                  |

This looks ugly, especially on non-maximized windows, where the folded-out menu will be drawn outside of the window for a large part.

I want it to look like this:

_______________________________________________________________
|File|____________________________________________________|-_X|
|   | Open            Ctrl+O|                                 |
|   | Save            Ctrl+S|                                 |
|   | Save As.. Ctrl+Shift+S|                                 |
|   | Exit            Alt+F4|                                 |

I've been trying to find out how to change this, but I couldn't find anything. I've tried things like HorizontalAlignment, HorizontalContentAlignment, but that does not work.

Also, I've noticed this menu orientation only with Windows 7, not with Windows XP. Lastly, this menu orientation is also in Visual Studio 2010 Express!

If any of you could provide me with an answer or a direction to search, I'd be very grateful.

Upvotes: 3

Views: 4139

Answers (5)

Eli Dagan
Eli Dagan

Reputation: 848

This happens in a machine with touch screen. On the start Menu Click:

Tablet PC Settings

Open the "Other" tab.

Change from "Right-Handed" to "Left-Handed"

Upvotes: 0

becky
becky

Reputation: 341

You have to change an entry in your registry.

The solution was posted here: WPF Sub-MenuItem Opening on the Left Instead of the Right

Upvotes: 0

Lukas Elmer
Lukas Elmer

Reputation: 333

It seems to be a configuration problem with your local windows machine (check if this behavior appears in other programs too). If yes, you have two possibilities to fix this:

Choice 1

  • Win+R
  • Enter "shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E}", press Ok
  • Under "Other" change Right-Handed to Left-Handed, press Ok

Your menus should open left-aligned.

Choice 2

  • Open your registry and change the following entry: [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\MenuDropAlignment] to "0"
  • Reboot

Upvotes: 5

Rohit Vats
Rohit Vats

Reputation: 81313

Try declaring the itemsPanelTemplate for the Menu like this -

  <Menu>
      <Menu.ItemsPanel>
          <ItemsPanelTemplate>
               <DockPanel HorizontalAlignment="Left"/>
          </ItemsPanelTemplate>
      </Menu.ItemsPanel>
    <MenuItem Height="auto" Header="{x:Static str:StringResources.File}">
        <MenuItem Header="{x:Static str:StringResources.Open}"
                  InputGestureText="Ctrl+O" 
                  Command="{Binding OpenFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.Save}" 
                  InputGestureText="Ctrl+S" 
                  Command="{Binding SaveFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.SaveAs}" 
                  InputGestureText="Ctrl+Shift+S" 
                  Command="{Binding SaveAsFileCommand}"/>
        <MenuItem Header="{x:Static str:StringResources.Exit}"
                  InputGestureText="Alt+F4"
                  Click="MenuItemExit_Click"
                  />
    </MenuItem>
</Menu>

Upvotes: 0

Grant Thomas
Grant Thomas

Reputation: 45068

You might try looking into FlowDirection, information at this MSDN page:

<MenuItem FlowDirection="LeftToRight">
</MenuItem>

Upvotes: 1

Related Questions