Pregunta

Tengo un cuadro de lista que se agrupar los artículos con una GroupStyle. Me gustaría agregar un control en la parte inferior de la StackPanel que contiene todos los grupos. Este necesidades de control adicionales para formar parte del contenido de desplazamiento de modo que el usuario vaya a la parte inferior de la lista para ver el control. Si estuviera usando un cuadro de lista sin los grupos, esta tarea sería fácil mediante la modificación de la plantilla de cuadro de lista. Sin embargo, con los elementos agrupados, la plantilla ListBox parece aplicarse únicamente en función de cada grupo. Puedo modificar el GroupStyle.Panel, pero eso no me permite añadir elementos a ese 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>

Esto debería dar una idea de lo que tengo que hacer:

GroupStyleNeeds

¿Fue útil?

Solución

You can use the strategy you were planning on for a ListBox, just do it for a GroupItem instead. If you add this XAML to your GroupStyle, it will add an end-of-group TextBlock:

<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>

Edit:

Here is a complete XAML-only example of a grouped list with a scrollbar and additional content added to the end of the scrolling region:

<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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top