I have been trying to bind the tabs in my XamRibbon to a collection to create them dynamically. I have been searching for ItemsSource properties and ItemContainerStyle with no luck. Can someone please provide an example? Thank you, Mike
It seems that the solution will be the workaround I mentioned in my first post. I tested this by having one set of RibbonGroups use ItemsSource binding and another explicitly generating the ribbon tools based on the same binding source. The second set of RibbonGroups worked fine with the QAT persistence. The ItemsSource RibbonGroups always generated their own Id properties regardless of element.Id binding in the DataTemplate and Tool Style. I don't know if this is something that IG development can look into as a bug or not.
Also, doing it this way there is no timing issue and the QAT items are properly added on Ribbon.Loaded event.
Unfortunately I think this will cause slower view load time and more complex code, but the QAT persistence will work.
Do you have a sample application that had all the pieces in place that you could share? If I play around with it, I may be able to come up with something.
Followup... the problem is not in the Id passed to the persistence logic. Apparently the problem is in the timing. When the persistence logic regenerates the QAT placeholders (on Ribbon.Loaded event), the dynamic RibbonGroups have not generated their contents. The result is that no Ribbon Tool is found that matches the placeholder Id and so it gets discarded.
I am currently adding the dynamic content on View.Loaded. I will have to see if I can load it earlier. Still, if you have any suggestions, I'd love to hear!
Thanks.
Hi Brian,
I have a XamRibbon configured with one explicitly defined RibbonTab in XAML. In this tab there are two explicitly defined RibbonGroups. At runtime several more RibbonGroups are added based on MVVM binding. The contents of the dynamic RibbonGroups is generated by binding the ItemsSource of the RibbonGroup to a collection on the RibbonGroup.DataContext. I am using implicit DataTemplate assignment for the Tools that populate the RibbonGroup. This is all working as expected.
Where I am running into a problem is with the QAT. All of my DataTemplates and Tool Styles bind the Id property of the tool to a unique identifier on the DataContext. We use code similar to the Samples Browser example to persist the user's QAT setup. However, all of the dynamically added content is getting an Id that does not match the binding unique identifier when added to the QAT. The QAT items have an Id that looks like it was generated automatically by the Ribbon. Because the Id is not found the next time the view is loaded, dynamically generated content is not persisted to the QAT.
I have considered an alternative way to generate the contents of the RibbonGroup by explicitly adding the tools when I generate the RibbonGroup instead of using the ItemsSource property and DataTemplating. I'd prefer NOT to do that because it complicates the code considerably.
Do you have any suggestions?
The XamRibbon is not an ItemsControl and therefore will not have an ItemsSource property. This was by design. You can still accomplish your goal by creating an attached property and binding your data to that. This will give you full control of how the tabs are added to the ribbon. This post shows how to use an attached property to data bind to the gallery tool. The concept is the exact same, you just have to modify it for ribbon tabs.
http://brianlagunas.com/2012/09/07/xamribboncreating-a-color-gallery-the-mvvm-way/