a·gen·tic a·gil·i·ty

Advice on using XamRibbon with Composite WPF

TL;DR; Provides guidance and code examples for integrating Infragistics XamRibbon with Composite WPF, including custom region adapters for dynamic tab and menu management.

Published on
3 minute read
Image
https://nkdagility.com/resources/gEnb0c6i-3I
Subscribe

Advice on using XamRibbon with Composite WPF

If, like me, you are interested in using all the new fangled controls produced by every man and his dog, you will probably have come across the Infragistics WPF control. My mission, that I stupidly accepted, was to update the TFS Sticky Buddy application with their XamRibbon and XamDockManager controls, and anything else I can stuff in there.

Advice on using XamRibbon with Composite WPF

The “anything else” I decided to use was the Composite WPF guidance. This is a newer WPF version of the Client Application Block (CAB) packages provided by the Patterns and Practices teams at Microsoft.

Anyhoo, I though I should give some advice for those of you mixing these technologies. I seam to have licked the XamRibbon implementation, but I am still working on the XamDockManager bits.

Note: You will need to be familiar with the Composite WPF bits for this all to make sense.

1   1: <igRibbon:XamRibbon  x:Name="uxXamRibbon" cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_Ribbon}"
2
3                           AllowMinimize="True" AutoHideEnabled="False" IsMinimized="False">
1   2:         <igRibbon:XamRibbon.ApplicationMenu>
1   3:           <igRibbon:ApplicationMenu cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_RibbonApplicationMenu}"
2
3                                           Image="/Hinshelwood.TFSStickyBuddy;component/RDIcon.ico">
1   4:             <igRibbon:ApplicationMenu.FooterToolbar>
1   5:               <igRibbon:ApplicationMenuFooterToolbar cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_RibbonApplicationMenuFooterToolbar}">
1   6:               </igRibbon:ApplicationMenuFooterToolbar>
1   7:            </igRibbon:ApplicationMenu.FooterToolbar>
1   8:         </igRibbon:ApplicationMenu>
1   9:      </igRibbon:XamRibbon.ApplicationMenu>
1  10: </igRibbon:XamRibbon>

As you can see there are a number of regions here, for the Tabs, the Application Menu and the FooterToolbar. You will need both a XamRibbon and a RibbonTabItem adapter.

1   1: Public Class RibbonRegionAdapter
1   2:     Inherits RegionAdapterBase(Of XamRibbon)
1   3:
1   4:     Private m_regionTarget As XamRibbon
1   5:
1   6:     Protected Overrides Sub Adapt(ByVal region As Microsoft.Practices.Composite.Regions.IRegion, ByVal regionTarget As XamRibbon)
1   7:         m_regionTarget = regionTarget
1   8:         regionTarget.Tabs.Clear()
1   9:         AddHandler region.ActiveViews.CollectionChanged, AddressOf OnActiveViewsChanged
1  10:         For Each v As RibbonTabItem In region.ActiveViews
1  11:             regionTarget.Tabs.Add(v)
1  12:         Next
1  13:
1  14:     End Sub
1  15:
1  16:     Private Sub OnActiveViewsChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
1  17:         Select Case e.Action
1  18:             Case NotifyCollectionChangedAction.Add
1  19:                 For Each v In e.NewItems
1  20:                     m_regionTarget.Tabs.Add(v)
1  21:                 Next
1  22:             Case NotifyCollectionChangedAction.Remove
1  23:                 For Each v In e.OldItems
1  24:                     m_regionTarget.Tabs.Remove(v)
1  25:                 Next
1  26:         End Select
1  27:     End Sub
1  28:
1  29:     Protected Overrides Function CreateRegion() As Microsoft.Practices.Composite.Regions.IRegion
1  30:         Return New AllActiveRegion
1  31:     End Function
1  32:
1  33: End Class
1   1: Public Class RibbonTabItemRegionAdapter
1   2:     Inherits RegionAdapterBase(Of RibbonTabItem)
1   3:
1   4:     Private m_regionTarget As RibbonTabItem
1   5:
1   6:     Protected Overrides Sub Adapt(ByVal region As Microsoft.Practices.Composite.Regions.IRegion, ByVal regionTarget As RibbonTabItem)
1   7:         m_regionTarget = regionTarget
1   8:         regionTarget.Content.Clear()
1   9:         AddHandler region.ActiveViews.CollectionChanged, AddressOf OnActiveViewsChanged
1  10:         For Each v As Object In region.ActiveViews
1  11:             regionTarget.Content.Add(v)
1  12:         Next
1  13:
1  14:     End Sub
1  15:
1  16:     Private Sub OnActiveViewsChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
1  17:         Select Case e.Action
1  18:             Case NotifyCollectionChangedAction.Add
1  19:                 For Each v In e.NewItems
1  20:                     m_regionTarget.Content.Add(v)
1  21:                 Next
1  22:             Case NotifyCollectionChangedAction.Remove
1  23:                 For Each v In e.OldItems
1  24:                     m_regionTarget.Content.Remove(v)
1  25:                 Next
1  26:         End Select
1  27:     End Sub
1  28:
1  29:     Protected Overrides Function CreateRegion() As Microsoft.Practices.Composite.Regions.IRegion
1  30:         Return New AllActiveRegion
1  31:     End Function
1  32:
1  33: End Class

I am pretty sure that these can be augmented, and I can think of a few Ideas already, including adding a re-parenting ability to allow menu items to be added to the XAML as well as programmatically added.

I think I might have to go away and try this…

Technorati Tags: WPF CodeProject

Smart Classifications

Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.

Subscribe

Connect with Martin Hinshelwood

If you've made it this far, it's worth connecting with our principal consultant and coach, Martin Hinshelwood, for a 30-minute 'ask me anything' call.

Our Happy Clients​

We partner with businesses across diverse industries, including finance, insurance, healthcare, pharmaceuticals, technology, engineering, transportation, hospitality, entertainment, legal, government, and military sectors.​

Schlumberger Logo

Schlumberger

Lockheed Martin Logo

Lockheed Martin

Illumina Logo

Illumina

DFDS Logo

DFDS

ALS Life Sciences Logo

ALS Life Sciences

Slicedbread Logo

Slicedbread

Alignment Healthcare Logo

Alignment Healthcare

Capita Secure Information Solutions Ltd Logo

Capita Secure Information Solutions Ltd

Philips Logo

Philips

Ericson Logo

Ericson

Slaughter and May Logo

Slaughter and May

YearUp.org Logo

YearUp.org

Deliotte Logo

Deliotte

Kongsberg Maritime Logo

Kongsberg Maritime

Hubtel Ghana Logo

Hubtel Ghana

Freadom Logo

Freadom

Xceptor - Process and Data Automation Logo

Xceptor - Process and Data Automation

Workday Logo

Workday

Ghana Police Service Logo

Ghana Police Service

Washington Department of Transport Logo

Washington Department of Transport

Royal Air Force Logo

Royal Air Force

Washington Department of Enterprise Services Logo

Washington Department of Enterprise Services

Department of Work and Pensions (UK) Logo

Department of Work and Pensions (UK)

Nottingham County Council Logo

Nottingham County Council

Microsoft Logo

Microsoft

Hubtel Ghana Logo

Hubtel Ghana

Workday Logo

Workday

MacDonald Humfrey (Automation) Ltd. Logo

MacDonald Humfrey (Automation) Ltd.

Qualco Logo

Qualco

Teleplan Logo

Teleplan