[EN] WPF: Ribbon in Prism Applications

Microsoft some time ago published its Ribbon(known from Office 2007) control library for Windows Presentation Foundation. However it turns out that obtaining this library is quite burdensome:

  1. You have to go to a ?Office UI Licensing? site and use ?License the Office UI?, next you have to login with your Live Id and accept license agreement. Frankly I have no idea what have I agreed to 😛 at the end you will be able to download WPFRibbonCTP, which contains ribbon control.
  2. I also strongly suggest to download Hands-On-Lab: What?s Coming in WPF:Datagrid, Ribbon and VSM which contains a great tutorial on how to use ribbon in your application. In exercise 2 there is a great app with ribbon which looks like this:


Using Ribbon in Prism

We had a talk on Prism on 12. Poznan .NET User Group Meeting. Szymon Kobalczyk gave a great talk on using Composite Application Library ( aka Prism ) to build great WPF applications. His presentation was very inspiring and gave me a kick-start into Prism. I decided to go on and use ribbon in prism. After some code reading it turned out that I just needed a custom RegionAdapter:

    public class RibbonControlRegionAdapter : RegionAdapterBase<Ribbon>
        private Ribbon m_regionTarget;

        protected override void Adapt(IRegion region, Ribbon regionTarget)
            m_regionTarget = regionTarget;
            region.ActiveViews.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(OnActiveViewsChanged);
            foreach ( RibbonTab v in region.ActiveViews)

        private void OnActiveViewsChanged(object sender, NotifyCollectionChangedEventArgs e)
            switch (e.Action)
                case NotifyCollectionChangedAction.Add:
                    foreach (RibbonTab v in e.NewItems)

                case NotifyCollectionChangedAction.Remove:
                    foreach (RibbonTab v in e.NewItems)


        protected override IRegion CreateRegion()
            return new AllActiveRegion();

Here is what shell aplication looks like before enabling a  test module ( I know ugly, but it?s not the point:P ):


This is how shell application looks like after enabling module1:


Further development

In this example custom region adapter is built in such way that it only allows you to add whole new tabs to ribbon. You can image an adapter that does reparenting and allows you to add regions even in tabs itself or items to main menu.

8 thoughts on “[EN] WPF: Ribbon in Prism Applications

  1. craig says:

    Where did you place this code, in the Composite.Wpf project under, Regions?

    Or did you create some infrastructure project and place the code in there?

    If you would be kind enough to email me your sample, I would be most greatful.

  2. hi, i don’t have access to src right now, but as far as i can recall i put it in my shell project

  3. craig says:

    Hi Bartłomiej

    Thanks for the reply. I’ve added the code-snippet to an Infrastructure project.

    In the Shell.xaml, I drop the Ribbon control, is that correct?

  4. craig,

    sure – that’s right!

  5. Craig says:

    ok, so I have my RegionAdaptor working, still a bit lost as to adding tabs and “items” to the ribbon from a module. Thanks for replying.

  6. Hi Bartek,
    Thanks for the article.

    I had some trouble with the DataBinding expressions inside the (detached) RibbonTabs.

    I’ve created an example solution to this problem here in case you are interested:


  7. Could you please post your code here or email it to me. Thank you 🙂

  8. I am not willing to share that code at the moment

Leave a Reply

Your email address will not be published. Required fields are marked *