ItemsControl和GroupStyle问题

时间:2018-01-11 14:27:19

标签: c# wpf itemscontrol groupstyle

以下代码为集合中的每个项生成UserControl。数据显示正确,但由于某些我无法理解的原因,所有UserControl都具有相同的大小。

See picture

如您所见,Group2包含多个StackPanel。所有这些StackPanel都具有相同的尺寸,并且不根据内容调整大小。

知道为什么吗?是因为ItemsPanelTemplate中定义的StackPanel?

            <CollectionViewSource x:Key="test" Source="{Binding}">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="Column"/>
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource> 

            <ItemsControl ItemsSource="{Binding Source={StaticResource test}}" HorizontalAlignment="Center">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <controls:Template/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.Panel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </GroupStyle.Panel>
                        </GroupStyle>
                    </ItemsControl.GroupStyle>
                </ItemsControl>

0 个答案:

没有答案