如何在WPF中使用右对齐菜单填充顶部
我是WPF的新手。我要右对齐菜单。但当将horizontalalignment属性设置为right时,它不会填充行的整个宽度。我使用水平对齐作为拉伸,但它不起作用。这是我的代码:如何在WPF中使用右对齐菜单填充顶部,wpf,menu,alignment,dock,Wpf,Menu,Alignment,Dock,我是WPF的新手。我要右对齐菜单。但当将horizontalalignment属性设置为right时,它不会填充行的整个宽度。我使用水平对齐作为拉伸,但它不起作用。这是我的代码: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions>
<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>
但我想:
---------------------------------
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>
Dock应该在第0行,不是吗?是的,你是对的,我编辑了代码,忘了更改其他内容中的网格?我将此代码粘贴到VS 2010上,看起来像你想要的那样不,它没有填充所有行,只是正确对齐
<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>