user4002899
user4002899

Reputation: 85

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

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

Answers (1)

Il Vic
Il Vic

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

Related Questions