protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Replace:
if (RibbonGallery != null)
{
object selectedItem = RibbonGallery.SelectedItem;
object highlightedItem = RibbonGallery.HighlightedItem;
if (selectedItem != null || highlightedItem != null)
{
for (int i = 0; i < e.OldItems.Count; i++)
{
if (selectedItem != null && RibbonGallery.VerifyEqual(selectedItem, e.OldItems[i]))
{
// Synchronize SelectedItem if it is one of
// the items being removed or replaced.
RibbonGallery.ForceCoerceSelectedItem();
break;
}
if (highlightedItem != null && RibbonGallery.VerifyEqual(highlightedItem, e.OldItems[i]))
{
// Synchronize HighlightedItem if it is one of
// the items being removed or replaced.
RibbonGallery.ForceCoerceHighlightedItem();
break;
}
}
}
RibbonGallery.IsMaxColumnWidthValid = false;
}
break;
case NotifyCollectionChangedAction.Reset:
if (RibbonGallery != null)
{
if (RibbonGallery.SelectedItem != null)
{
// Synchronize SelectedItem after a Reset operation.
RibbonGallery.ForceCoerceSelectedItem();
}
if (RibbonGallery.HighlightedItem != null)
{
// Synchronize HighlightedItem after a Reset operation.
RibbonGallery.ForceCoerceHighlightedItem();
}
RibbonGallery.IsMaxColumnWidthValid = false;
}
break;
case NotifyCollectionChangedAction.Add:
if (RibbonGallery != null)
{
RibbonGallery.IsMaxColumnWidthValid = false;
}
break;
case NotifyCollectionChangedAction.Move:
break;
}
}