3

グループ スタイルの ListBox があります。

<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>

バインドされたコレクションが変更されると、エキスパンダーが再度開かれます。ユーザーの設定を記憶し、エキスパンダーを折りたたんだままにする方法はありますか?

4

2 に答える 2

1

問題は、バインドされたコレクションで何をしているのかです。最良の選択肢は、ビューモデルにエキスパンダーをバインドするプロパティを持たせることであるというニコライに同意します。

最初に私が尋ねた質問については、CollectionView を少し更新していますか? Refresh により、UI が再作成されます。(つまり、ObservableCollection のリセットのようなものです。ユーザー コントロールを作成し、テンプレートの XAML を再度読み込むように UI に指示しますが、パフォーマンスが低下します)。

于 2012-08-21T15:08:25.820 に答える
0

簡単なハックを提案できます。IsExpandedプロパティをモデルクラスに追加し、Expander.IsExpandedをそれにバインドするだけです。

于 2012-04-16T07:31:56.617 に答える