Martin Hinshelwood (MrHinsh) on Visual Studio ALM

A Scottish software developer | ALM Consultant | Microsoft Visual Studio ALM MVP | Microsoft Visual Studio ALM Ranger | Professional Scrum Developer Trainer
posts - 444, comments - 722, trackbacks - 57

My Links

News

Profile photo of Martin Hinshelwood Martin Hinshelwood on LinkedIn
Martin Hinshelwood on Twitter
Martin Hinshelwood on Facebook
Martin Hinshelwood on Messenger
Martin Hinshelwood on Feedburner

Martin is an ALM Consultant, and also one of three Microsoft Visual Studio ALM MVP in the UK and has over 9 years experience in the software industry. Martin has recently joined the ranks of the Microsoft Visual Studio ALM Rangers deliver out of band solutions for missing features or guidance.

Microsoft Visual Studio ALM MVP

Martin speaks at DDD Scotland, one of the top events in the UK along with a number of User Groups across UK and Europe. And is excited to be presenting the Professional Scrum Developer course which he is one of only three qualified trainers in the UK.

Professional Scrum Developer Trainer Certified ScrumMaster

He aims to continue improve the engineering practices of development teams in the UK and Europe. He does this by migrating them to, and coaching them in the use of, Microsoft’s ALM offering in combination with Scrum. These offerings include Team Foundation Server (TFS) and Visual Studio.

Microsoft Certified Technical Specialist: Team Foundation Server  

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Locations of visitors to this page

Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

Blogs I read

Blogs of Friends

Personal

Projects

VSTS

Advice on using XamRibbon with Composite WPF

image

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.

pnp.gif

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: <igRibbon:XamRibbon x:Name="uxXamRibbon" cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_Ribbon}"

AllowMinimize="True" AutoHideEnabled="False" IsMinimized="False">

   2:         <igRibbon:XamRibbon.ApplicationMenu>

3: <igRibbon:ApplicationMenu cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_RibbonApplicationMenu}"

Image="/Hinshelwood.TFSStickyBuddy;component/RDIcon.ico">

   4:             <igRibbon:ApplicationMenu.FooterToolbar>
   5:               <igRibbon:ApplicationMenuFooterToolbar cal:RegionManager.RegionName="{x:Static inf:RegionNames.Shell_RibbonApplicationMenuFooterToolbar}">
   6:               </igRibbon:ApplicationMenuFooterToolbar>
   7:            </igRibbon:ApplicationMenu.FooterToolbar>
   8:         </igRibbon:ApplicationMenu>
   9:      </igRibbon:XamRibbon.ApplicationMenu>
  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: Public Class RibbonRegionAdapter
   2:     Inherits RegionAdapterBase(Of XamRibbon)
   3:  
   4:     Private m_regionTarget As XamRibbon
   5:  
   6:     Protected Overrides Sub Adapt(ByVal region As Microsoft.Practices.Composite.Regions.IRegion, ByVal regionTarget As XamRibbon)
   7:         m_regionTarget = regionTarget
   8:         regionTarget.Tabs.Clear()
   9:         AddHandler region.ActiveViews.CollectionChanged, AddressOf OnActiveViewsChanged
  10:         For Each v As RibbonTabItem In region.ActiveViews
  11:             regionTarget.Tabs.Add(v)
  12:         Next
  13:  
  14:     End Sub
  15:  
  16:     Private Sub OnActiveViewsChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
  17:         Select Case e.Action
  18:             Case NotifyCollectionChangedAction.Add
  19:                 For Each v In e.NewItems
  20:                     m_regionTarget.Tabs.Add(v)
  21:                 Next
  22:             Case NotifyCollectionChangedAction.Remove
  23:                 For Each v In e.OldItems
  24:                     m_regionTarget.Tabs.Remove(v)
  25:                 Next
  26:         End Select
  27:     End Sub
  28:  
  29:     Protected Overrides Function CreateRegion() As Microsoft.Practices.Composite.Regions.IRegion
  30:         Return New AllActiveRegion
  31:     End Function
  32:  
  33: End Class

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

Print | posted on Wednesday, November 19, 2008 5:03 PM | Filed Under [ WPF CodeProject ]

Feedback

Gravatar

# re: Advice on using XamRibbon with Composite WPF

I'm trying to convert the code to C#, but I am stuck on line 8, 11, 20, and 24 of the RibbonTabItemRegionAdapter. There is no Clear, Add, or Remove method on the Content property. It's of type Object. I am using Infragistics WPF v8.2. Any ideas?
11/22/2008 1:15 AM | James
Gravatar

# re: Advice on using XamRibbon with Composite WPF

I'm new to this, but i'll risk sounding stupid.
Shouldn't you be calling Add, Clear, Remove against RibbonGroups instead of Content.
1/22/2009 12:54 PM | Priyanka
Gravatar

# re: Advice on using XamRibbon with Composite WPF

Hello Martin,

first, thank you for your XamRibbon regionadapter!!
Your adapter worked well until I decided to upgrade
my project to the Feb.2009 version of Composite WPF.
Now it seems that the regionmanager does now not
recognize all XamRibbon regions. I get the following
error. "The region manager does not contain the Shell_Ribbon
region". I.e. If I check the regionmanger after beeing
injected into a module constructor it contains just
the "Shell_RibbonApplicationMenu" region and
the "Shell_RibbonApplicationMenuFooterToolbar" region

"Shell_Ribbon" region is missing!

Do you have any idea how to fix this?

Greetings and thank you.
Hannes
3/24/2009 8:17 AM | hh
Gravatar

# re: Advice on using XamRibbon with Composite WPF

How to create ribbonregion adapter using Infragistics 9.1 and PRISM. Tabs has to be dynamically created in the XamRibbonRegion from the Modules.

Thank You,
techincal reseach
7/7/2009 7:49 PM | Technical Research
Comments have been closed on this topic.

Powered by: