使用WrapPanel样式化ListView.GroupStyle

|| 好的,这是我的简单问题。 我设置了一个“ 0”样式,以使其看起来像Windows资源管理器。 现在,我想将项目分组。因此,我定义了
GroupStyle
和an2ѭ进行分组。分组现在很好。 我现在不喜欢的是,我的
ListView
将每个组显示在单独的行上,而我想进行一些扩展器包装,以便在同一行上显示许多组。 我猜图像比文字更好。 这是我所拥有的: 这是我想要的: 我找不到为使ѭ4适应WrapPanel而必须设置样式的属性,就像我为商品所做的那样。 这是我的ListView样式:
<ResourceDictionary>

                    <!-- Explorer-style layout-->
                    <DataTemplate x:Key=\"ExplorerView\">
                        <StackPanel Orientation=\"Horizontal\" Height=\"Auto\" Width=\"150\">
                            <Image Source=\"{Binding Path=Value.AppConfig.Appli.AppType, Converter={StaticResource TypeToIconConverter}}\" Margin=\"5\"
                                   Height=\"50\" Width=\"50\"/>
                            <StackPanel VerticalAlignment=\"Center\" Width=\"90\">
                                <TextBlock Text=\"{Binding Path=Value.AppConfig.Appli.AppName}\" 
                     FontSize=\"13\" HorizontalAlignment=\"Left\" TextWrapping=\"WrapWithOverflow\"
                     Margin=\"0,0,0,1\" />
                                <TextBlock Text=\"{Binding Path=Value.AppConfig.Appli.AppType}\" FontSize=\"9\" 
                     HorizontalAlignment=\"Left\" Margin=\"0,0,0,1\" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>

                    <!-- Group header style-->
    <Style x:Key=\"GroupHeaderStyle\" TargetType=\"{x:Type GroupItem}\">


        <Setter Property=\"Template\">
            <Setter.Value>
                <ControlTemplate TargetType=\"{x:Type GroupItem}\">

                    <Expander x:Name=\"exp\" IsExpanded=\"True\" Width=\"310\"
                                   BorderBrush=\"CornflowerBlue\">

                        <Expander.Header>
                            <DockPanel HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\"
                                        Background=\"CornflowerBlue\" x:Name=\"expContent\"
                                        Width=\"{Binding RelativeSource={RelativeSource
                                            Mode=FindAncestor, AncestorType={x:Type Expander}},
                                            Path=Width}\"
                                        Height=\"{Binding RelativeSource={RelativeSource
                                            Mode=FindAncestor, AncestorType={x:Type ToggleButton}},
                                            Path=ActualHeight}\">
                                <CheckBox IsChecked=\"False\" DockPanel.Dock=\"Right\"/>
                                <TextBlock Text=\"{Binding Path=Name}\" Foreground=\"White\"
                                           FontWeight=\"Bold\" HorizontalAlignment=\"Center\" />
                            </DockPanel>
                        </Expander.Header>
                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



                </ResourceDictionary>
    <!-- (...) -->

    <ListView ItemsSource=\"{Binding GroupedConfig, Mode=TwoWay}\" 
              ItemTemplate=\"{StaticResource ExplorerView}\">



        <ListView.ItemsPanel>
            <ItemsPanelTemplate >
                <WrapPanel Width=\"{Binding (FrameworkElement.ActualWidth),
                     RelativeSource={RelativeSource 
                                     AncestorType=Expander}}\"
                     ItemWidth=\"{Binding (ListView.View).ItemWidth,
                     RelativeSource={RelativeSource AncestorType=ListView}}\"

                     ItemHeight=\"{Binding (ListView.View).ItemHeight,
                     RelativeSource={RelativeSource AncestorType=ListView}}\" />
                <!--MinWidth=\"{Binding ItemWidth,
                     RelativeSource={RelativeSource Self}}\"-->
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>

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


    </ListView>
有任何想法吗? 我试图以为
GroupItem
定义的样式插入一些适当的
Setter
,但是我开始认为这不是正确的方法。 谢谢!
已邀请:
经过多次尝试,我终于找到了正确的属性进行编辑。 我想如果有人需要做一些具有相同行为的事情,将其发布在这里可能会很有用: 因此,实际上我们在
GroupStyle
中有一个属性
Panel
,可以在其中添加所需的
WrapPanel
<ListView.GroupStyle>
    <GroupStyle ContainerStyle=\"{StaticResource GroupHeaderStyle}\">
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <WrapPanel Width=\"800\" />
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
    </GroupStyle>
</ListView.GroupStyle>
如果有人在这里,例如我正在尝试制作ListBox项目包装,但是基于未知数量的项目,因此您无法像上面的答案一样设置Width,这就是我的方法。
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
    <WrapPanel Orientation=\"Vertical\" MaxHeight=\"{Binding Converter={StaticResource ListBoxHeightToItemsPanelHeightConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualHeight}\"/> 
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
在我的转换器中,我只需减去30就可以考虑标头的高度。 这是完整的代码:
<ListBox.GroupStyle>
<GroupStyle>
    <GroupStyle.HeaderTemplate>
        <DataTemplate>
            <TextBlock Margin=\"8\" FontSize=\"18\" TextAlignment=\"Center\" FontWeight=\"Bold\" Foreground=\"White\" >
                <TextBlock.Text>
                    <Binding Path=\"Name\"/>
                </TextBlock.Text>
            </TextBlock>
        </DataTemplate>
    </GroupStyle.HeaderTemplate>
    <GroupStyle.Panel>
        <ItemsPanelTemplate>
            <StackPanel Orientation=\"Horizontal\"/>
        </ItemsPanelTemplate>
    </GroupStyle.Panel>
</GroupStyle>
</ListBox.GroupStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
    <WrapPanel Orientation=\"Vertical\" MaxHeight=\"{Binding Converter={StaticResource ListBoxHeightToGroupStyleHeightConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualHeight}\"/> 
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Template>
<ControlTemplate>
    <!-- Your template here. -->
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate >
    <!-- Your template here. -->
</DataTemplate>
</ListBox.ItemTemplate>
希望这可以帮助节省一些时间!

要回复问题请先登录注册