Reputation: 85
I’m new in WPF. I want a right alignment menu. But when set horizontalalignment property to right, it don’t fill the whole width of row. I use horizontalcontentalignment as stretch but it does’nt work. 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?
Upvotes: 1
Views: 285
Reputation: 5666
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>
Upvotes: 2