6

I have a WPF app that I am working on. Everything is very simple at the moment as I've not implemented any of the "meat" yet. One of the things that is bothering some of the users with the prototype is that the menu drops down "backwards" from how it used to in win forms.

enter image description here

What I'm looking to have is the left edge of the menu box line up with the left edge of the word "File" in the parent menu. I've been doing some searching but I don't think I'm hitting the right keywords. I'm not sure if it makes any difference but I'm also using the MVVMLight library by Galasoft.

My question is how do I get the left edge of the menu to line up with the left edge of the "File" text? Thanks ahead of time!

    <Menu Grid.Row="0" Grid.Column="0">
        <MenuItem Header="_File" >
            <MenuItem Header="EnableWatcher" IsCheckable="True" IsChecked="{Binding WatcherEnabled}" />
            <Separator />
            <MenuItem Header="_Exit" />
        </MenuItem>
    </Menu>

EDIT: Here is all of the code in the xaml file.

    <Window x:Class="DonkeySuite.Watcher.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:DonkeySuite.Watcher.ViewModel"
    Title="MainWindow" Height="350" Width="525" Icon="/DonkeySuite.Watcher;component/BlueFolder.ico">
<Window.DataContext>
    <ViewModel:MainViewModel />
</Window.DataContext>
<!--<i:Interaction.Triggers>
    <i:EventTrigger EventName="Closing">
        <Command:EventToCommand Command="{Binding SaveSettings}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>-->
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="30" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>

    </Grid.ColumnDefinitions>
    <Menu Grid.Row="0" Grid.Column="0">
        <MenuItem Header="_File" >
            <MenuItem Header="EnableWatcher" IsCheckable="True" IsChecked="{Binding WatcherEnabled}" />
            <Separator />
            <MenuItem Header="_Exit" />
        </MenuItem>
    </Menu>

    <Grid Grid.Column="0" Grid.Row="1">
        <Grid.RowDefinitions>

        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="60" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="100" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center">Directory:</TextBlock>
        <TextBox Grid.Column="1" Text="{Binding WatchDirectory, Mode=TwoWay}" VerticalAlignment="Center"></TextBox>
        <Button Grid.Column="2" Content="Browse" Command="{Binding BrowseForDirectory}" Height="24" Margin="5, 0, 15, 0">
        </Button>
    </Grid>
</Grid>

Frito
  • 1,423
  • 1
  • 15
  • 27
  • Honestly, it should, and there is nothing weird in your above code xaml that would make that happen. Makes me think the surrounding XAML might be the problem, or a resource dictionary that you're using. Plus, does this happen when your app is maximized? – Phil Jun 28 '12 at 04:34
  • Hey Phil. Thanks for the comment. I added another MenuItem at the same level as "_File" and am still seeing the results when the form is maximized. The left most menu lines up correctly because it's against the left edge of the viewable area. The second item then pushes left into the first items area. – Frito Jun 28 '12 at 12:15
  • Very weird. I copied your code verbatim (except for the viewmodel part, of course), and it worked exactly as it should, which is the way you want. The only way i got the menu to appear to the left like your example was by moving the window to the right off the screen, which is again what i would expect. There is nothing wrong with your code. Are you using an application level resource dictionary by any chance? – Phil Jun 28 '12 at 16:15
  • No, I'm not using anything else that affects the xaml. I have literally opened VS2010, used nuGet to get the MVVMLite libraries. Put some test data in my `MainViewModel` and wrote the above. That's what is really driving me nuts about this. I can copy this project out of the solution and make it available for download at the same place I have the screen snippet when I get off work. I'm almost beginning to wonder if it's a setting on my machine or something. Most everyone I've asked at work have said the code block above should just work as well. – Frito Jun 28 '12 at 21:28
  • I just got home and copied my bin\Debug folder to another machine. The drop downs work just fine there. I guess this is some kind of configuration issue on my machine. I've checked all my Location / Culture data on the computer and everything seems to be fine. Menu's on everything else work as expected (FireFox, Outlook, etc.). I'll have to do some more digging when I get time and hopefully I can post an answer in the future. Dang annoying 'bug' *grumble grumble grumble*... – Frito Jun 28 '12 at 23:00

1 Answers1

24

I finally figured it out. I found a link off Microsoft that resolved my issue. Apparently this was happeneing because I have a Wacom tablet on my computer. It has absolutely nothing to do with WPF.

http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/menus-are-being-right-aligned/cb94ff1e-5c3f-4535-944a-ae5632149a0d

In case the link ends up going away here's the details in a nut-shell.

Press the Windows key + R to bring up the Run dialog box. In the Open line, copy/paste the following line of text.

shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E}

Press OK.

This will start the Tablet PC Settings configuration dialog (Even if you do not have a Tablet PC).

Select the Other Tab.

In the Handedness section, place a check mark in the Left Handed option.

Click OK.

Frito
  • 1,423
  • 1
  • 15
  • 27
  • 1
    Pretty odd it does not affect all menus in all programs. So I never noticed this. Thank you! – Matt Mar 21 '18 at 12:02
  • Anyone have an idea how this can be resolved for each user's deployment? – David Savage Apr 16 '19 at 07:36
  • 1
    @DavidSavage ~ At app startup, you can set this registry value: `HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\MenuDropAlignment`. Set it to `0`. If GPO is available to you, though, that's a better way. Ref [here](https://stackoverflow.com/a/37037081). – InteXX Apr 14 '20 at 23:51
  • Even though I've searched quite a lot, this answer actually solved it – MKZ Jun 07 '21 at 13:50
  • This really helpful! You saved my day! – BOBIN JOSEPH Oct 29 '21 at 08:37