相关疑难解决方法(0)

如何在列表视图的组头中保存IsExpanded状态

我有一个非常棘手的问题:

我正在使用ListView控件,其ItemsSource设置为CollectionViewSource,包括PropertyGroupDescription以对ListView元素进行分组.CollectionViewSource看起来像这样:

<CollectionViewSource x:Key="ListViewObjects">
   <CollectionViewSource.Source>
      <Binding Path="CurrentListViewData"/>
   </CollectionViewSource.Source>
   <CollectionViewSource.GroupDescriptions>
      <PropertyGroupDescription PropertyName="ObjectType" />
   </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
Run Code Online (Sandbox Code Playgroud)

在ListView中,我使用自定义组头,如下所示:

<ListView.GroupStyle>
   <GroupStyle>
      <GroupStyle.ContainerStyle>
         <Style TargetType="{x:Type GroupItem}">
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Template">
               <Setter.Value>
                  <ControlTemplate TargetType="{x:Type GroupItem}">
                     <Expander IsExpanded="True">
                        <Expander.Header>
                           <DockPanel>
                              <TextBlock Text="{Binding Path=Items[0].ObjectType />
                           </DockPanel>
                        </Expander.Header>
                        <Expander.Content>
                           <ItemsPresenter />
                        </Expander.Content>
                     </Expander>
                  </ControlTemplate>
               </Setter.Value>
            </Setter>
         </Style>
      </GroupStyle.ContainerStyle>
   </GroupStyle>
</ListView.GroupStyle>
Run Code Online (Sandbox Code Playgroud)

如您所见,Expander的IsExpanded属性设置为true.这意味着每当刷新ListView时,都会扩展所有Expander控件.

但是我想保存每个Expander的最后状态.我无法找到一种方法来保存每个ObjectType的Expander状态列表.我正在尝试使用绑定的HashTable和Converter,但是我没有将ObjectType作为ConverterParameter提供,因为它总是作为字符串传递.但这可能不是解决方案.

有人可以给我一个解决方案的提示或想法吗?:)

c# data-binding wpf xaml

16
推荐指数
2
解决办法
4173
查看次数

标签 统计

c# ×1

data-binding ×1

wpf ×1

xaml ×1