Setting Ribbon Group.ItemsSource results in an OutOfMemoryException

Ribbon for WPF Forum

Posted 8 years ago by Michael Rumpler
Version: 16.1.0633
Platform: .NET 4.5
Environment: Windows 10 (64-bit)

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);

	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.

Comments (2)

Posted 8 years ago by Michael Rumpler

I made my own Group which overrides the ItemsSource property and does the foreach above which fills the Items collection. This seems to work.

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Michael,

Thanks for the sample.  We'll reply to the support ticket email.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.