【问题标题】:WPF: Use diffrenent orientation for grouped ICollectionViewWPF:对分组的 ICollectionView 使用不同的方向
【发布时间】:2017-10-27 14:57:04
【问题描述】:

我有一个分组的ListCollectionView,它显示在ListBox 中。

    <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <StackPanel>
                        <Label Content="{Binding Path=Name}"/>
                        <WrapPanel Orientation="Horizontal">                                
                            <ItemsPresenter />
                        </WrapPanel>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ListBox ItemsSource="{Binding MyElementView, Mode=OneWay}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.GroupStyle>
            <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}" />
        </ListBox.GroupStyle>

        <ListBox.ItemTemplate>
            <DataTemplate DataType="{x:Type model:MyElementViewModel}">
                ...
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

现在所有元素都以垂直方式列出,但我想将组水平放置,但组内的项目应该垂直列出。我怎么可能意识到?

【问题讨论】:

    标签: c# wpf listbox icollectionview


    【解决方案1】:

    GroupStyle 有一个 Panel 属性,您可以将其设置为 ItemsPanelTemplate

    <ListBox ...>
        <ListBox.GroupStyle>
            <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
            </GroupStyle>
        </ListBox.GroupStyle>
        <ListBox.ItemTemplate>
            <DataTemplate>
                ...
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 2017-01-03
      • 2010-11-16
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多