WPF 菜单位置不正常
我一直很高兴地编写我的新程序,它的工作非常顺利。它很简单,一开始不需要菜单,直到我决定添加更多功能,所以需要菜单。咩!下图更好地解释了我的问题。
注意到文件菜单是如何对齐的吗?图片中的应用程序是一个测试应用程序,只是为了看看我是否在其他应用程序中添加了可能导致问题的内容。尽管该项目是全新的,但它仍然出现了。我不明白为什么会这样。有人经历过吗?由于某种原因,具有设置命令的菜单项也会被禁用。取消设置菜单项则不会。您可以看到上面显示的“退出”菜单项已被禁用。在下面的代码中,它设置为“ApplicationCommands.Close”。
顺便说一句,我正在使用 Windows 7 x64 并使用 Visual Studio 2010 编写 WPF 应用程序。非常感谢您的帮助!提前致谢!
<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'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 if 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一篇旧帖子,但问题与我几周前遇到的问题类似,我通过这条路线解决了它。
Windows 有一个触摸/平板电脑设置,您可以在其中填写您是左手还是右手。这确定了上下文菜单的位置,以确保在触摸屏设备导致问题的情况下您的手不会覆盖菜单。
进入控制面板-->硬件和声音 -->平板电脑的。并在名为“其他”的第三个选项卡中选择左撇子。这会将菜单定位在菜单按钮的另一侧。
已编辑
看来 DevilFisch 和我都使用 Wacom 数位板,这可能是导致此问题的原因。使用平板电脑或类似设备时,会触发平板电脑设置,从而导致上述问题。
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.
关于导致禁用菜单项的命令,如果没有相应的命令绑定,则这是预期的。至于对齐问题,您是否尝试过不在 XAML 中设置显式大小?例如:
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: