PhiLong
Topic Author
Posts: 10
Joined: 16 Mar 2017, 04:51

How do I right-align the 'help' menu item

09 Apr 2017, 11:06

In WPF I can use the below to right-align the 'help' menu
<Menu Height="20" Background="#FFA9D1F4">
            <Menu.ItemsPanel>
                <ItemsPanelTemplate>
                    <DockPanel HorizontalAlignment="Stretch"/>
                </ItemsPanelTemplate>
            </Menu.ItemsPanel>
            <MenuItem Header="File">
                <MenuItem Header="Exit"/>
            </MenuItem>
            <MenuItem Header="Edit">
                <MenuItem Header="Cut"/>
            </MenuItem>
                <MenuItem Header="Help" HorizontalAlignment="Right">
                    <MenuItem Header="About"/>
                </MenuItem>
        </Menu>
+-------------------------------------------+
| File Edit                            Help |
+-------------------------------------------+
|                                           |
Could I do it in Noesis GUI?
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: How do I right-align the 'help' menu item

09 Apr 2017, 12:59

Could you try to explicitly set the width of the menu to some large number, and observe the effect?
Peter Verswyvelen,
Strongly Typed Solutions
 
nokola
Posts: 186
Joined: 10 Mar 2015, 05:29

Re: How do I right-align the 'help' menu item

10 Apr 2017, 07:52

Instead of HorizontalAlignment="Right" for the help menu can you try DockPanel.Dock="Right"? That might work. https://wpftutorial.net/DockPanel.html
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: How do I right-align the 'help' menu item

10 Apr 2017, 17:36

I tried playing with this code in Kaxaml and the Noesis XamlPlayer, and as far as I can tell, this is a bug, Menu seems to ignore the ItemsPanel completely.

For example, the following code

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
   <Menu Foreground="White">
      <Menu.ItemsPanel>
         <ItemsPanelTemplate>
         <StackPanel IsItemsHost="True" Orientation="Vertical" Background="Skyblue"/>
         </ItemsPanelTemplate>
      </Menu.ItemsPanel>
      <MenuItem Header="File">
         <MenuItem Header="Exit"/>
      </MenuItem>
      <MenuItem Header="Edit">
         <MenuItem Header="Cut"/>
      </MenuItem>
      <MenuItem Header="Help">
         <MenuItem Header="About"/>
      </MenuItem>
   </Menu>
</UserControl>
still layouts each MenuItem horizontally stacked
Peter Verswyvelen,
Strongly Typed Solutions
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: How do I right-align the 'help' menu item

10 Apr 2017, 17:55

If I include the Noesis style into the XAML, the WPF version also fails. So it seems the default Noesis Menu template is wrong. Investigating further.
Peter Verswyvelen,
Strongly Typed Solutions
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: How do I right-align the 'help' menu item

10 Apr 2017, 18:08

Indeed, the builtin Noesis style for Menu is wrong (well actually, so is the MSDN documentation).

I assume you're using `NoesisStyle.xaml` as your theme.

Open `NoesisStyle.xaml`, and search for `<Style TargetType="{x:Type Menu}"`.

Then replace the following code
<StackPanel IsItemsHost="True" Orientation="Horizontal"/>
by
<ItemsPresenter/>
Peter Verswyvelen,
Strongly Typed Solutions
 
nokola
Posts: 186
Joined: 10 Mar 2015, 05:29

Re: How do I right-align the 'help' menu item

11 Apr 2017, 03:40

Good find! I recommend report it on the bug tracker.
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: How do I right-align the 'help' menu item

11 Apr 2017, 11:37

Working on it! I'll provide a patch too.
Peter Verswyvelen,
Strongly Typed Solutions
 
User avatar
sfernandez
Site Admin
Posts: 1652
Joined: 22 Dec 2011, 19:20

Re: How do I right-align the 'help' menu item

11 Apr 2017, 19:04

Thanks for all the investigation here Ziriax.
We will include the patch in the following release.

PhiLong, meanwhile you can override default template in the Menu to apply the patch locally:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
   <Menu Foreground="White">
      <Menu.Template>
         <ControlTemplate TargetType="Menu">
            ...
         </ControlTemplate>
      </Menu.Template>
      <Menu.ItemsPanel>
         <ItemsPanelTemplate>
            <DockPanel IsItemsHost="True" LastChildFill="False"/>
         </ItemsPanelTemplate>
      </Menu.ItemsPanel>
      <MenuItem Header="File" DockPanel.Dock="Left">
         <MenuItem Header="Exit"/>
      </MenuItem>
      <MenuItem Header="Edit" DockPanel.Dock="Left">
         <MenuItem Header="Cut"/>
      </MenuItem>
      <MenuItem Header="Help" DockPanel.Dock="Right">
         <MenuItem Header="About"/>
      </MenuItem>
   </Menu>
</UserControl>
 
User avatar
sfernandez
Site Admin
Posts: 1652
Joined: 22 Dec 2011, 19:20

Re: How do I right-align the 'help' menu item

25 Apr 2017, 11:27

Default styles fixed in NoesisGUI 2.0.1 to use ItemsPresenter in all the items controls.

Who is online

Users browsing this forum: Bing [Bot] and 1 guest