2011-01-15 49 views
4

GroupStyleでアイテムをグループ化しているリストボックスがあります。私はすべてのグループを保持するスタックパネルの下部にコントロールを追加したいと思います。この追加のコントロールは、スクロールするコンテンツの一部である必要があります。そのため、ユーザーはリストをスクロールしてコントロールを表示します。グループなしでリストボックスを使用していた場合、ListBoxテンプレートを変更することでこの作業は簡単になります。ただし、アイテムをグループ化すると、ListBoxテンプレートはグループごとにのみ適用されるようです。 GroupStyle.Panelを変更することはできますが、そのパネルにアイテムを追加することはできません。WPFのグループパネルListBox

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

これは私が何をする必要があるかのアイデアを与える必要があります。

GroupStyleNeeds

+0

画像を正確に描画します。 ListBoxの後にコントロールを追加し、テンプレートを変更することはできないと思うからです。 – vorrtex

答えて

8

あなただけのためにそれを行う、あなたはListBoxのために計画された戦略を使用することができます代わりにGroupItem。あなたはGroupStyleにこのXAMLを追加した場合、それは終わりのグループ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> 

編集:ここでは

は、スクロールバーでグループ化されたリストの完全な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> 
+0

この度はありがとうございます。問題は、各グループにテキストブロックを追加することです。私はすべてのグループの最後に何かが必要です。 – rulestein

+0

その場合、 'ListBox'テンプレートの影響を受けたグループの修正が間違っているというあなたの元々の結論を言います。 **何か**はグループを含んでいなければならず、 'GroupItem'ではありません。私は完全な例を投稿します。 –

+0

完全な例をありがとうございました。リストボックスのテンプレートが私のために働いていなかった理由はわかりませんが、あなたの例は必要なものです。 – rulestein