private void OnCurrentItemChanged()
{
Debug.Assert(RibbonGallery == null || RibbonGallery.IsSynchronizedWithCurrentItemInternal, "We shouldn't be listening for currency changes if IsSynchronizedWithCurrentItemInternal is false");
if (RibbonGallery == null || CollectionView == null || RibbonGallery.IsSelectionChangeActive)
{
return;
}
RibbonGalleryItem galleryItem = this.ItemContainerGenerator.ContainerFromItem(CollectionView.CurrentItem) as RibbonGalleryItem;
if (galleryItem != null)
{
// This is fast path to have the SelectedItem set
galleryItem.IsSelected = true;
}
else
{
// This is to handle UI virtualization scenarios where the
// container for the CurrentItem may not have been generated.
RibbonGallery.SelectedItem = CollectionView.CurrentItem;
}
}