Skip to content

Commit

Permalink
Fixes #256 by relying on ItemContainerGenerator instead of invoking a…
Browse files Browse the repository at this point in the history
…sync action on dispatcher
  • Loading branch information
batzen committed Feb 5, 2016
1 parent 6e68696 commit 750a9eb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Fluent.Ribbon/Controls/GalleryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
using Fluent.Internal;

/// <summary>
/// Represents panel for Gallery, InRibbonGallery, ComboBox
Expand Down Expand Up @@ -249,6 +250,7 @@ public GalleryPanel()
#region Visual Tree

private readonly VisualCollection visualCollection;
private ItemContainerGeneratorAction itemContainerGeneratorAction;

/// <summary>
/// Gets the number of visual child elements within this element.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -605,9 +612,12 @@ protected override IEnumerator LogicalChildren
/// <param name="sender">The <see cref="T:System.Object"/> that raised the event.</param><param name="args">Provides data for the <see cref="E:System.Windows.Controls.ItemContainerGenerator.ItemsChanged"/> event.</param>
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);
}
}
}

0 comments on commit 750a9eb

Please sign in to comment.