Binding ApplicationMenu contents

Ribbon for WPF Forum

Posted 14 years ago by AlexanderB - Software Developer, Edifecs
Version: 10.1.0523

I cannot bind ApplicationMenu items to collection in code-behind. Here is simplified example of what I try to do


<ribbon:Ribbon Grid.Row="0" x:Name="Ribbon">
    <ribbon:ApplicationMenu Name="AppMenu">
          <ribbon:Button Label="{Binding Label}"/>

public MainRibbonWindow()

  ObservableCollection<RibbonMenuItem> items = new ObservableCollection<RibbonMenuItem>();
  items.Add(new RibbonMenuItem("Hello1"));
  items.Add(new RibbonMenuItem("Hello2"));
  items.Add(new RibbonMenuItem("Hello3"));
  items.Add(new RibbonMenuItem("Hello4"));
  items.Add(new RibbonMenuItem("Hello5"));
  AppMenu.ItemsSource = items;

public class RibbonMenuItem
  public RibbonMenuItem(String label)
    _label = label;

  private String _label;
  public String Label
      return _label;
After executing the code, Application menu of ribbon control will be empty. I want it to contain 5 items: "Hello1", ..., "Hello5".

I guess the reason is that ApplicationMenu doesn't host ribbon:Button directly, but wraps it with ribbon:MenuItem. How to write it in ApplicationMenu's ItemTemplate definition to make binding work?

Thanks in advise

Comments (3)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Thanks for the sample. We need to pass the ItemTemplate on in the ApplicationMenu control template to the contained Menu control. We've added this for the next version.

Specifically if you have the XAML default templates, here's what we did:
<ribbonControls:Menu ItemTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemTemplate}"
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Items}" />
Then if you do this in your data template it works:
<ribbon:Button Label="{Binding Label}" Context="MenuItem" VariantSize="Large"/>

Actipro Software Support

Posted 14 years ago by AlexanderB - Software Developer, Edifecs
Thank you!

As I understood, this issue is fixed in the latest WPF Studio Release (2010.2 build 0530), isn't it?

Anyway, one additional question:
Is there some way to work with contained Menu control directly? For example, set it's ItemsSource/ItemsTemplate in code-behind. If yes, how can to get Menu control from ApplicationMenu? I was not able to find it with VisualTreeHelper.

Thanks in advance,
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Alexander,

Yes that should be updated in 2010.2.

We don't expose anything to access the Menu in the template directly. You shoudl be able to find it with a recursive VisualTreeHelper search once the template has been loaded for the ApplicationMenu though.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.