简体   繁体   English

我怎样才能在WPF中填充右对齐菜单

[英]how can i have a right alignment menu fill top in WPF

I'm new in WPF. 我是WPF的新手。 I want a right alignment menu. 我想要一个正确的对齐菜单。 But when set horizontalalignment property to right, it don't fill the whole width of row. 但是,当将horizo​​ntalalignment属性设置为right时,它不会填满行的整个宽度。 I use horizontalcontentalignment as stretch but it does'nt work. 我使用horizo​​ntalcontentalignment作为拉伸,但是它不起作用。 This is my code: 这是我的代码:

    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"></ColumnDefinition>
      </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="60" />
        <RowDefinition Height="*" />
        <RowDefinition />
    </Grid.RowDefinitions>


    <DockPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right">
        <Menu DockPanel.Dock="Top" >
            <MenuItem Header="_File"/>
            <MenuItem Header="_Edit"/>
            <MenuItem Header="_Help"/>
        </Menu> 
     </DockPanel>
</Grid>

What is displayed is as below: 显示内容如下:

    -----------------------------
    File edit help              |
    -----------------------------

But I want to be: 但我想成为:

   ---------------------------------
                     Help edit file|
    --------------------------------

How can I get menu fill top and set it's alignment to right? 如何获得顶部的菜单并将其对齐方式设置为正确?

You can do something like that: 您可以执行以下操作:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="60" />
        <RowDefinition Height="*" />
        <RowDefinition />
    </Grid.RowDefinitions>

    <Menu Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch">
        <Menu.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Top" />
            </ItemsPanelTemplate>
        </Menu.ItemsPanel>

        <MenuItem Header="_File" />
        <MenuItem Header="_Edit"/>
        <MenuItem Header="_Help"/>
    </Menu>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM