diff --git a/Fluent.Ribbon/Controls/GalleryPanel.cs b/Fluent.Ribbon/Controls/GalleryPanel.cs index e5abc710f..d47648ee3 100644 --- a/Fluent.Ribbon/Controls/GalleryPanel.cs +++ b/Fluent.Ribbon/Controls/GalleryPanel.cs @@ -11,6 +11,7 @@ using System.Windows.Data; using System.Windows.Media; using System.Windows.Threading; + using Fluent.Internal; /// /// Represents panel for Gallery, InRibbonGallery, ComboBox @@ -249,6 +250,7 @@ public GalleryPanel() #region Visual Tree private readonly VisualCollection visualCollection; + private ItemContainerGeneratorAction itemContainerGeneratorAction; /// /// Gets the number of visual child elements within this element. @@ -379,6 +381,11 @@ private void RefreshDispatchered() private void Refresh() { + if (this.itemContainerGeneratorAction == null) + { + this.itemContainerGeneratorAction = new ItemContainerGeneratorAction((ItemContainerGenerator)this.ItemContainerGenerator, this.Refresh); + } + // Clear currently used group containers // and supply with new generated ones foreach (var galleryGroupContainer in this.galleryGroupContainers) @@ -605,9 +612,12 @@ protected override IEnumerator LogicalChildren /// The that raised the event.Provides data for the event. protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args) { - base.OnItemsChanged(sender, args); + if (this.itemContainerGeneratorAction?.IsWaitingForGenerator == false) + { + this.itemContainerGeneratorAction?.QueueAction(); + } - this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(this.Refresh)); + base.OnItemsChanged(sender, args); } } } \ No newline at end of file