WPF 菜单位置不正常

发布于 2024-10-11 02:52:03 字数 1150 浏览 9 评论 0原文

我一直很高兴地编写我的新程序,它的工作非常顺利。它很简单,一开始不需要菜单,直到我决定添加更多功能,所以需要菜单。咩!下图更好地解释了我的问题。

image

注意到文件菜单是如何对齐的吗?图片中的应用程序是一个测试应用程序,只是为了看看我是否在其他应用程序中添加了可能导致问题的内容。尽管该项目是全新的,但它仍然出现了。我不明白为什么会这样。有人经历过吗?由于某种原因,具有设置命令的菜单项也会被禁用。取消设置菜单项则不会。您可以看到上面显示的“退出”菜单项已被禁用。在下面的代码中,它设置为“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.

image

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-10-18 02:52:03

我知道这是一篇旧帖子,但问题与我几周前遇到的问题类似,我通过这条路线解决了它。

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.

十六岁半 2024-10-18 02:52:03

关于导致禁用菜单项的命令,如果没有相应的命令绑定,则这是预期的。至于对齐问题,您是否尝试过不在 XAML 中设置显式大小?例如:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文