I'm trying to have text in the top level of a RibbonApplicationMenu (trying to the get the word "File" there similar to Word or Outlook). It seems the Microsoft.Windows.Controls.Ribbon.RibbonApplicationMenu
http://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon.ribbonapplicationmenu.aspx supports a SmallImageSource but no text property. Setting the Label
property doesn't work for this problem.
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
<ribbon:RibbonApplicationMenu Label="File"> <!--doesn't set the label -->
</ribbon:RibbonApplicationMenu>
The goal is to have the word "File" appear in the circled area below.
The simplest solution (to me) was to insert a DrawingImage with a GlyphRun inside. On a separate post is asked how to get the AdvanceWidths and GlyphIndicies for the GlyphRun. The result is below
Resulting Ribbon:
Another way to do so is just using a grid and paint a TextBlock at the right place. Be sure to make the TextBlock NOT HitTestVisible.
Advantages:
Disadvantage: - looks less nice on Windows XP
Right. If you want no code-behind and no complex glyph computations, use the following XAML:
Advantages of this approach:
Tricky! You might have to replace the PART_ToggleButton of the template with your own version to be able to set the text.
Using the WPF Vizualizer shows that the template contains a StackPanel with an Image and a Path (DownArrow), but no TextBlock, so I doubt that there is a place in the current control to specify the label text.
Of course, you could also create an image that contains the desired text.
Remove the unwanted elements for the visual tree, and replace them with a TextBlock that takes the text from the Label property. You have to do this for both the button on the main visual tree and on the popup's visual tree. Finally, since text is more intricate than the typical image, it is helpful to back off on the aero highlighting effects.
To use the following code, assign a name to the application menu in the XAML and call
ReplaceRibbonApplicationMenuButtonContent
with it from the Loaded event handler of the window.