Home > Enterprise >  How I can align MenuItems in Menu to right?
How I can align MenuItems in Menu to right?

Time:11-22

I want to get 'RUN' and 'ADD' items to right instead of left, but it isn't going to right

I tried to use:

<Menu>
            <Menu.ItemsPanel>
                <ItemsPanelTemplate>
                    <DockPanel HorizontalAlignment="Stretch"/>
                </ItemsPanelTemplate>
            </Menu.ItemsPanel>
            <MenuItem Header="FILE"/>
            <MenuItem Header="EDIT"/>
            <MenuItem Header="VIEW"/>
            <MenuItem Header="RUN" HorizontalAlignment="Right"/>
            <MenuItem Header="ADD" HorizontalAlignment="Right"/>
        </Menu>

I expect that 'RUN' and 'ADD' items will go to right

but I got

CodePudding user response:

Your issue is in the

<ItemsPanelTemplate>
    <DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>

This is what describes the container your MenuItems will belong in. You need to use a panel here which allows you to horizontally align items to the right within it.

You could try keeping it as a DockPanel:

<DockPanel LastChildFill="False" HorizontalAlignment="Stretch"> 

And adding

DockPanel.Dock="Right"

To the MenuItems you need to align right, and

DockPanel.Dock="Left"

To the others. If this does not work, there are plenty of other panels you can use in place of the DockPanel in the ItemsPanelTemplate.

  • Related