
I understand that your Ribbon was not built with MVVM in mind. I tried to extend it on my own to support this.
This worked well with my own StackPanel which adds an ItemsSource property. The items in that collection are meant to be ViewModels. The respective UIElement (type of StackPanel.Children) is created via a DataTemplate defined in the ResourceDictionary.
When I tried to use the ItemsSource on the Group (Group inherits from ItemsControl and should support that natively), then the app seems to run in an endless loop. Memory consumption goes up, but it never returns.
This can be seen in my CreateGroup method:
private Group CreateGroup(RibbonGroup ribbonGroup)
{
var group = (Group)GetView(ribbonGroup);
//var group = new Group()
//{
// Label = ribbonGroup.Caption,
// Tag = ribbonGroup.Id,
// ItemsSource = ribbonGroup.RibbonLayouts.ToList(), // OutOfMemory
//};
//group.SetBinding(ItemsControl.ItemsSourceProperty, nameof(RibbonGroup.RibbonLayouts)); // OutOfMemory
//group.ItemsSource = ribbonGroup.RibbonLayouts; // OutOfMemory
//group.ItemsSource = ribbonGroup.RibbonLayouts.Select(l => GetView(l)); // doesn't find DataTemplates in the StackPanels
foreach (var ribbonLayout in ribbonGroup.RibbonLayouts) // works
{
var view = GetView(ribbonLayout);
group.Items.Add(view);
}
return group;
}
You can usualy add ViewModels to ItemsControl.ItemsSource and it takes DataTemplates into account to convert them to Views. But this doesn't work for a Group. I have to convert the ViewModels to a UIElement myself and add them to the Items collection. But if I do that, then I have to manually react on changes in my binding source. I cannot just bind an ObservableCollection.
I couldn't find how to attach a sample project to this bug in the web so I'll send it via email.