微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有一个我正在研究的WPF应用程序.目前一切都很简单,因为我还没有实施任何“肉”.使用原型困扰一些用户的事情之一是菜单从赢取表单中的“向后”方向下降.

我期待的是菜单框的左边缘与父菜单中单词“File”的左边缘对齐.我一直在做一些搜索,但我认为我没有找到合适的关键词.我不确定它是否有任何区别,但我也使用galasoft的MVVMLight库.

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

<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,15,0">
        </Button>
    </Grid>
</Grid>

解决方法

我终于弄明白了.我发现微软的一个链接解决了我的问题.显然这是因为我的计算机上有一台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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐