Fluent Ribbon and Prism

I would like to show an example of application that is about how to use Fluent Ribbon control together with Prism (aka Composite WPF). Our team is using this combination for some time already; although, with various degrees of success: the Fluent Ribbon is not enough mature (but pretty stable) and my personal relation with Prism is kind of love/hate. The Castle Winsor is starring as IoC Container of choice.

The code is not something extraordinary by any means. You can find lots of similar samples for other controls in the net. It’s just a sample how to use these libraries together.

In this example I’ve set next scenario: a module (or another part of application) wants to add new RibbonTabItem to existing Ribbon without having a direct reference to it. Also, application should support activation/deactivation and removing of Tabs.

The basics are pretty straightforward: pick/write an IRegion, write an adapter to work as a mediator between it and control being extended, profit!..

I’ve decided to use an existing Region to serve as host for tabs – SingleActiveRegion. It seems to fit well expected behavior.

Two classes that I wrote are RibbonRegionAdapter and RibbonRegionSyncBehavior. The behavior class is used to synchronize the Tabs collection of the Ribbon with Views and ActiveViews collections of the SingleActiveRegion. Adapter serves only to instantiate the region and attach the behavior.

Also, this solution uses Castle Windsor to wire up all things. The WindsorBootstrapper class wires up an application based on Prism v2.2 and Castle.

I’ll not publish the the code here, you can “git clone …” it from repository on GitHub. Or, from the same place, you have the option to download sources.

Future plans include few more regions (Backstage, RibbonTabItem) and may be some tests.

Solution specifics:

  • Prism v2.2
  • Fluent Ribbon rev. 51299
  • Castle Windsor 2.1.1
  • VS 2010 & NET 4.0

Disclaimer: code is provided “AS IS”. It may contain bugs and not be written in best possible way. I’m not a Prism specialist by any means. Any help is welcome if somebody can improve this code or wants to contribute for a more meaningful example…

Advertisement
  1. #1 by Fresh on September 21, 2010 - 00:28

    Nice!

    What about the buttons? How do you activate/deactivate them depending on the current view

    • #2 by Valeriu Caraulean on September 21, 2010 - 08:31

      Well, it’s obvious that you should have your buttons bound to any kind of ICommand in order to get activation/deactivation.

      But where that ICommand should live, that’s a more interesting question. We’re using MVVM pattern. Then, it depends on scenario: sometimes we have a separate ViewModel for a RibbonTabItem or even for a ribbon Group. Then we have a mechanism to communicate with other View Models or Controllers. It can be Prism’s event aggregator or any other mechanism of choice. But in some cases we’re binding it directly to commands in current “content ViewModel”. In this case the ViewModel is just declaring commands without implementing them and we have a kind of “controller” linking together these two ViewModels.

      But it’s really depending on your specific requirements and current structure of the application.

  2. #3 by Fresh on September 22, 2010 - 19:59

    Thanks much for the comment.

    That points me on the right direction. I was still living with the SCSF’s UIExtension mindset.

  3. #4 by Paul on November 4, 2010 - 23:36

    I am using your RibbonRegionAdapter, by the excellent work. I am adding RibbonTabItems via modules and registering them to the Ribbon Region. My delima is there a way to specify which order they get added. For instance I have Module A and Module B, currently Module B is first ans I need Module A to be first.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.