I've been happily writing my new program and it worked like a charm. It was simple and didn't need a menu at first until I decided to add more functionality so a menu was required. Baam! The image below explains my problem better.
Noticed how the file menu is aligned? The app in the picture is a test app just to see i开发者_开发知识库f I added something in my other app that may have caused the problem. Even though the project was brand new it still showed up. I can't understand why it's happening. Has anyone ever experienced this? MenuItems with set commands also get disabled for some reason. Unset MenuItems don't. You can see that the "Exit" MenuItem shown above is disabled. In the code below it's set to "ApplicationCommands.Close".
By the way, I'm using Windows 7 x64 and writing the WPF app with Visual Studio 2010. A helping hand will be very much appreciated! Thanks in advance!
<Window x:Class="TestDrive.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">
<Grid>
<Menu Height="23" HorizontalAlignment="Left" Name="menu1" VerticalAlignment="Top" Width="200">
<MenuItem Header="File">
<MenuItem Command="ApplicationCommands.Close" Header="Exit" />
</MenuItem>
<MenuItem Header="Edit" />
</Menu>
</Grid>
</Window>
I know it is an old post but the problem is similar to the one I had a few weeks ago and I solved it via this route.
Windows has a Touch/TabletPCs setting where you can fill in whether you are left or right handed. This determines the positioning of the contextmenu to make sure your hand is not covering the menu in case of touchscreen devices which is causing the problem.
Go to Control Panel --> Hardware and Sounds --> Tablet PC's. And choose left-handed in the third tab called 'Other'. This will position the menu on the other side of the menubutton.
EDITED
It seems that both DevilFisch and I are using a Wacom pen tablet which could be the cause of this issue. When using a pentablet or something alike, Tablet PC settings are triggered causing the afformentioned issues.
Regarding commands resulting in disabled menu items, that is expected if there is no corresponding command binding. As for the alignment issue, have you tried not setting explicit sizes in your XAML? For example:
<Window x:Class="TestDrive.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Command="ApplicationCommands.Close" Header="Exit" />
</MenuItem>
<MenuItem Header="Edit" />
</Menu>
</DockPanel>
</Window>
精彩评论