Okay, after many hours of try and error, I found a possible way to do it. It's not the 100% original behaviour like in "Windows 7 Paint" or similar Windows 7 ribbon applications, but in most cases it works.
First, you need to know that the application menu is realized with a Popup
, which has a Placement
property to define where the popup is opened. You need to override the default behaviour to PlacementMode.Left
. This will make the popup menu open up right next to the menu button.
Next, you need to set the Popup.HorizontalOffset
property to the negated RibbonApplicationMenu.Width
. This is done via Binding and a converter to negate the value.
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.Resources>
<Style TargetType="Popup">
<Setter Property="Placement" Value="Left"/>
<Setter Property="HorizontalOffset" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=r:RibbonApplicationMenu}, Path=Width, Converter={StaticResource ResourceKey=NegateIntegerConverter}}"/>
</Style>
</r:RibbonApplicationMenu.Resources>
</r:RibbonApplicationMenu>
The converter is defined in the RibbonWindow.Resources
as follows:
<r:RibbonWindow.Resources>
<local:NegateIntegerConverter x:Key="NegateIntegerConverter"/>
</r:RibbonWindow.Resources>
The local
namespace has to be declared inside of the RibbonWindow
:
<r:RibbonWindow x:Class="MainWindow"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:local="clr-namespace:ApplicationRootNamespace"
>
And finally, the code for the NegateIntegerConverter
is a class in the application's root namespace:
Public Class NegateIntegerConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Return -CInt(value)
End Function
Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return -CInt(value)
End Function
End Class
Class MainWindow
End Class
Now for the difference in behaviour: if the menu cannot fully expand to the right because the screen is ending there, the popup does not simply open up a bit farther to the left, but completely on the left. Maybe I can find out how it's actually behaving like the "Windows 7 Paint" ribbon's menu, but this is a good workaround until then.