问题描述
我有一个自定义的 Ribbongallery 控件,例如 Excel、MSWord 和 Outlook。
请参考下面的 Excel Ribbongallery 图片,正常选择仍然存在。
我保留了两个 ItemsSource,一个用于 Ribbongallery View,一个用于 Popup,并在 Ribbongallery 和 Popup View 中排列项目。
当我在 Ribbongallery 中选择一个项目时,SelectedItem(对象)的选择将被更新。如果我打开一个弹出窗口,我会从 Ribbongallery 中清除 ItemsSource(为了避免 Element 已经添加了另一个元素问题的子项)并将其重新分配给 Popup ItemsControl。但是在打开/关闭弹出窗口后,所选项目的选择被清除。
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 从 ItemsControl Tapped 事件更新。
有人请告诉我在将新集合更新到控件时如何保留选择(Ribbongallery 到 popup 和 popup 到 Ribbongallery)?