I have a custom RibbonGallery control like in Excel, MSWord, and Outlook.
Please refer the Excel RibbonGallery image below and Normal selection still exists.
And I kept two ItemsSource, one for RibbonGallery View and one for Popup, and arranged the items in RibbonGallery and Popup View.
When I choose an item in RibbonGallery, the selection of SelectedItem (object) will be updated. If I open a popup, I cleared ItemsSource from the RibbonGallery (inorder to avoid the Element already added the child of another element issue) and reassigned it to the Popup ItemsControl. But the selection of the selected item is cleared after open/closing the popup.
private void UpdateItemsSource()
{
if (!this.IsDropDownOpen)
{
this.popupGalleryItemsControl.ItemsSource = null;
this.ribbonGalleryItemsControl.ItemsSource = this.ItemsSource;
}
else
{
this.ribbonGalleryItemsControl.ItemsSource = null;
this.popupGalleryItemsControl.ItemsSource = this.ItemsSource;
}
}
<ItemsControl x:Name="RibbonGalleryItemsControl"
ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
ItemTemplate="{TemplateBinding ItemTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ItemsControl x:Name="PopupItemsControl"
ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
ItemTemplate="{TemplateBinding ItemTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
SelectedItem updated from ItemsControl Tapped event.
Anybody please tell me how to retain the selection when updating new collection to the control (RibbonGallery to popup and popup to RibbonGallery)?