繁体   English   中英

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

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

我是WPF的新手。 我想要一个正确的对齐菜单。 但是,当将horizo​​ntalalignment属性设置为right时,它不会填满行的整个宽度。 我使用horizo​​ntalcontentalignment作为拉伸,但是它不起作用。 这是我的代码:

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

显示内容如下:

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

但我想成为:

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

如何获得顶部的菜单并将其对齐方式设置为正确?

您可以执行以下操作:

<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