wpf - 如何让 WPF 菜单像旧的 win 表单菜单一样对齐?

标签 wpf

我有一个正在开发的 WPF 应用程序。目前一切都非常简单,因为我还没有实现任何“肉”。使用原型(prototype)困扰一些用户的一件事是,菜单从以前在 win 表单中的方式“向后”下拉。

enter image description here

我正在寻找的是菜单框的左边缘与父菜单中"file"一词的左边缘对齐。我一直在做一些搜索,但我认为我没有找到正确的关键字。我不确定它是否有任何区别,但我也在使用 Galasoft 的 MVVMLight 库。

我的问题是如何让菜单的左边缘与"file"文本的左边缘对齐?提前谢谢!

    <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 文件中的所有代码。
    <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 完全无关。

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

万一链接最终消失,这里是一个坚果壳中的详细信息。

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.

关于wpf - 如何让 WPF 菜单像旧的 win 表单菜单一样对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11237378/

相关文章:

c# - 如何处理在 WPF (C#) 中制作带参数的窗口?

c# - ViewModel 的暴露数据取决于 View 的大小

c# - 如何为 Mesh3D 正确设置纹理坐标

c# - 绑定(bind)到显式接口(interface)实现的 SortDescription

WPF:如何禁用 SystemMenu 快捷方式 'Alt+Space' ?

wpf - 在 XAML 中创建指向文本文件的链接

c# - 如何使默认的 TreeView (System.Windows.Controls) 具有与 RadTreeView (telerik) 相同的样式?

c# - 如何将 ScrollBar 添加到 Stackpanel

c# - 如何在 WPF 应用程序上执行异步启动?

wpf - Control.Focus() 和 FocusManager.SetFocusedElement() 的区别