Search code examples
c#wpfvisual-studio-2010xamlribbon

Right align (Help) button on WPF ribbon


I'm attempting to add a Help button on the right side of the tabs in my WPF Ribbon app. I'm using the "WPF Ribbon Application" template is Visual Studio 2010, by the way. This is what I have so far:

<ribbon:Ribbon x:Name="Ribbon">
    <ribbon:Ribbon.ApplicationMenu>
        <ribbon:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
            <ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
                                                x:Name="MenuItem1"
                                                ImageSource="Images\LargeIcon.png"/>
        </ribbon:RibbonApplicationMenu>
    </ribbon:Ribbon.ApplicationMenu>
    <ribbon:RibbonTab x:Name="HomeTab" 
                        Header="Home">            
    </ribbon:RibbonTab>
    <ribbon:RibbonButton x:Name="HelpButton" 
                        SmallImageSource="Images\help.ico">
    </ribbon:RibbonButton>
</ribbon:Ribbon>

This results in a left-aligned help button: Left-aligned help button. Not what I'm looking for.

However, I want a right-aligned help button like one sees in MS Word 2010: Right-aligned help button. This is what I'm looking for.

I've seen a suggestion to just adjust the margin on the button. While this does move the button to the right, it doesn't follow the edge of the window when the window is resized. Likewise, there's a similar question on SO to mine, but if you follow the answer, they're talking about ribbon groups, not buttons adjacent to the ribbon tabs.


Solution

  • Don't add the help button as a simple RibbonButton, use a HelpPaneContent element instead.

    Don't do this :

    <ribbon:RibbonButton x:Name="HelpButton" 
           SmallImageSource="Images\help.ico">
    </ribbon:RibbonButton>
    

    Do this instead :

    <ribbon:Ribbon.HelpPaneContent>
          <ribbon:RibbonButton x:Name="HelpButton" SmallImageSource="Images\help.ico"/>
    </ribbon:Ribbon.HelpPaneContent>