Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF列表框的组面板_Wpf_Listbox_Groupstyle_Itemspaneltemplate - Fatal编程技术网

WPF列表框的组面板

WPF列表框的组面板,wpf,listbox,groupstyle,itemspaneltemplate,Wpf,Listbox,Groupstyle,Itemspaneltemplate,我有一个列表框,它使用GroupStyle对项目进行分组。我想在stackpanel的底部添加一个控件,用于保存所有组。此附加控件需要是滚动内容的一部分,以便用户滚动到列表底部以查看该控件。如果我使用的是一个没有组的列表框,那么通过修改列表框模板,这项任务将很容易完成。但是,对于分组的项目,ListBox模板似乎只适用于每个组。我可以修改GroupStyle.Panel,但这不允许我向该面板添加项目 <ListBox> <ListBox.ItemsPanel> &

我有一个列表框,它使用GroupStyle对项目进行分组。我想在stackpanel的底部添加一个控件,用于保存所有组。此附加控件需要是滚动内容的一部分,以便用户滚动到列表底部以查看该控件。如果我使用的是一个没有组的列表框,那么通过修改列表框模板,这项任务将很容易完成。但是,对于分组的项目,ListBox模板似乎只适用于每个组。我可以修改GroupStyle.Panel,但这不允许我向该面板添加项目

<ListBox>
<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.GroupStyle>
    <GroupStyle>
         <GroupStyle.Panel>
             <ItemsPanelTemplate>
                 <VirtualizingStackPanel/>  **<----- I would like to add a control to this stackpanel**
             </ItemsPanelTemplate>
         </GroupStyle.Panel>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                     <Setter.Value>
                         <ControlTemplate TargetType="{x:Type GroupItem}">
                              <Grid>
                                  <ItemsPresenter />
                              </Grid>
                         </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListBox.GroupStyle>


** 您可以使用您为
列表框
计划的策略,只需为
组项目
执行即可。如果将此XAML添加到
组样式
,它将添加组的末尾
文本块

<GroupStyle.ContainerStyle>
    <Style TargetType="GroupItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <StackPanel>
                        <ContentPresenter/>
                        <ItemsPresenter Margin="5,0,0,0"/>
                        <TextBlock Text="*** End of group ***"/>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</GroupStyle.ContainerStyle>

编辑:

下面是一个完整的仅限XAML的分组列表示例,其中包含一个滚动条和添加到滚动区域末尾的其他内容:

<Grid Height="100">
    <Grid.Resources>
        <PointCollection x:Key="sampleData">
            <Point X="1" Y="1"/>
            <Point X="1" Y="2"/>
            <Point X="2" Y="3"/>
            <Point X="2" Y="4"/>
            <Point X="3" Y="5"/>
            <Point X="3" Y="6"/>
        </PointCollection>
        <CollectionViewSource x:Key="groupedSampleData" Source="{StaticResource sampleData}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="X" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Grid.Resources>
    <ListBox ItemsSource="{Binding Source={StaticResource groupedSampleData}}">
        <ListBox.Template>
            <ControlTemplate TargetType="{x:Type ListBox}">
                <ScrollViewer CanContentScroll="True">
                    <StackPanel>
                        <ItemsPresenter/>
                        <TextBlock Text="*** End of list ***"/>
                    </StackPanel>
                </ScrollViewer>
            </ControlTemplate>
        </ListBox.Template>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=Y}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.GroupStyle>
            <GroupStyle>
                <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel/>
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Margin="4" FontWeight="Bold" FontSize="15" Text="{Binding Path=Name}"/>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ItemsControl.GroupStyle>
    </ListBox>
</Grid>


画一幅你想要的图片。因为我认为你可以在列表框之后添加控件,而不必更改模板。谢谢你的建议。问题是将textblock添加到每个组中。我需要在所有组的末尾添加一些内容。在这种情况下,我会说您最初的结论,即修改受影响组的
列表框
模板是不正确的。某些内容必须包含组,而不是
GroupItem
。我将发布一个完整的示例。非常感谢您提供完整的示例。我不知道为什么listbox模板在我处理它的时候对我不起作用,但是你的例子正是我所需要的。