How to set up CollectionView grouping based on data template settings

I have a ListBox with a group style:

<GroupStyle HidesIfEmpty="True" x:Key="GroupStyle">
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Margin" Value="0,0,0,5"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                    <Expander.Header>
                                        <DockPanel Background="LightSkyBlue" 
                                                           Width="{Binding RelativeSource={RelativeSource  Mode=FindAncestor,  AncestorType={x:Type Expander}},
                                                                           Path=ActualWidth}">
                                            <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                            <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                        </DockPanel>
                                    </Expander.Header>
                                    <Expander.Content>
                                        <ItemsPresenter/>
                                    </Expander.Content>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>

Any changes to the associated collection cause the expanders to reopen. Is there any way to remember user settings and leave unfolding expanders?

+3
source share
2 answers

The question is what are you doing with the related collection. I agree with Nikolai that the best option is to have your model viewmodel properties with which you will bind the expander.

, : CollectionView? . (, Reset ObservableCollection. XAML , ).

+1

- IsExpanded Expander.IsExpanded .

0

All Articles