0

以下に示すように、グループ化を実装し、グループスタイル内にエキスパンダーを定義したリストビューがあります。

<ListView.GroupStyle>
                    <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" >
                                                <Expander.Header>
                                                    <DockPanel>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                                        <TextBlock FontWeight="Bold" Text=" Items"/>
                                                    </DockPanel>
                                                </Expander.Header>
                                                <Expander.Content>
                                                    <ItemsPresenter />
                                                </Expander.Content>
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListView.GroupStyle>

エキスパンダーを変更して、1 つだけが展開され、複数ある場合は残りが折りたたまれるようにします。また、エキスパンダーのいずれかをプログラムで展開したい場合、つまり cs からオブジェクトを追加し、そのエキスパンダーを表示したいとします。開いた、それは可能なはずです、何か提案はありますか?? 前もって感謝します

編集:リストビューとグループをバインドするコード:

CollectionViewSource viewSource = new CollectionViewSource { Source = TO_DOlst };
        viewSource.GroupDescriptions.Add(new PropertyGroupDescription("timeCategory"));
        lstView.ItemsSource = viewSource.View;

timecategory はクラスのメンバーです

4

1 に答える 1

0

Name と同じように、クラスにブール値のプロパティを作成して IsExpanded プロパティをバインドし、CS ですべてのビジネス ルールを直接定義できます。

if(ItemsSource.Count() > 1)
  //set IsExpanded = false;
else
  // set only first item and so on.

よろしく。

于 2012-09-05T20:05:20.923 に答える