如何让 WPF 菜单像旧的 win 表单菜单一样对齐? [英] How can I get WPF menus to align like the old win forms menu?

查看:35
本文介绍了如何让 WPF 菜单像旧的 win 表单菜单一样对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在开发的 WPF 应用程序.目前一切都非常简单,因为我还没有实现任何肉".使用原型让一些用户感到困扰的一件事是菜单从它过去在 win 表单中的方式向后"下拉.

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.

我想要的是菜单框的左边缘与父菜单中文件"一词的左边缘对齐.我一直在做一些搜索,但我认为我没有找到正确的关键字.我不确定它是否有什么不同,但我也在使用 Galasoft 的 MVVMLight 库.

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>

这是 xaml 文件中的所有代码.

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>

推荐答案

我终于想通了.我找到了 Microsoft 的链接,解决了我的问题.显然这是因为我的电脑上有一个 Wacom 平板电脑.它与 WPF 完全无关.

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.

Windows 键 + R 调出运行对话框.在打开行,复制/粘贴以下文本行.

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}

确定.

这将启动平板电脑设置配置对话框(即使你没有平板电脑).

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

选择其他标签.

惯用手部分,勾选惯用左手选项.

点击确定.

这篇关于如何让 WPF 菜单像旧的 win 表单菜单一样对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆