0

ItemsControl にグループ化を追加しました。

        <ItemsControl Style="{StaticResource SellingDashboardToDosList}" Grid.Row="2" BorderThickness="1" Background="#C7E8F8" HorizontalAlignment="Stretch" ItemsSource="{Binding ToDoList}" >
            <ItemsControl.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="GroupItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="GroupItem">
                                        <GroupBox Header="{Binding Name}">
                                            <ItemsPresenter />
                                        </GroupBox>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ItemsControl.GroupStyle>
        </ItemsControl>

空の GroupBox だけが表示されるようになりました。Snoop ツールを使用してアプリケーションを調査したところ、GroupBox ItemPresenters が空であることがわかりました。その理由は何でしょうか?

ItemsControl (ItemsControl.GroupStyle 要素) からグループ化を削除すると、すべてが正常に機能し、すべての項目が再び表示されます。すべてのアイテムを表示するために、基になるデータ コンテキストを変更する必要はありません。データ コンテキスト (ItemsSource binging) はCollectionViewSource型です。

バインディング トレースがオンになっていますが、バインディング エラーは表示されません。

4

2 に答える 2

1

ItemsControl スタイルが ItemsControl.Template プロパティをオーバーライドしていたようです。そのスタイルがオーバーライドされると、問題は解決しました。

于 2012-07-16T13:26:02.147 に答える
0

最初にデータをグループ化する必要があります。これを行うには CollectionViewSource を使用します。

<CollectionViewSource x:Key="Data" Source="{StaticResource SellingDashboardToDosList}">
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="PropertyNameToGroupBy"/>
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

そうして初めて、次のことができます。

<ItemsControl ItemsSource="{Biding Source={StaticResource Data}}" ...
于 2012-07-16T11:26:32.987 に答える