GroupStyle.HeaderTemplate 속성


그룹 머리글을 표시하는 데 사용되는 템플릿을 가져오거나 설정합니다.Gets or sets the template that is used to display the group header.

 property System::Windows::DataTemplate ^ HeaderTemplate { System::Windows::DataTemplate ^ get(); void set(System::Windows::DataTemplate ^ value); };
public System.Windows.DataTemplate HeaderTemplate { get; set; }
member this.HeaderTemplate : System.Windows.DataTemplate with get, set
Public Property HeaderTemplate As DataTemplate

속성 값

그룹 머리글을 표시하는 데 사용되는 DataTemplate 개체입니다.A DataTemplate object that is used to display the group header. 기본값은 null입니다.The default is null.


다음 예제에 나온을 ItemsControl 에 바인딩되는 XmlDataProvider 콘텐츠와 코드 숨김 논리를 추가 하 고 그룹화 제거를 포함 하는.The following examples show an ItemsControl that is bound to an XmlDataProvider and the code-behind content that contains the logic to add and remove grouping. 확인란은 확인 하는 경우,의 콘텐츠를 ItemsControl 그룹화 됩니다는 Type 특성입니다.When the check box is checked, the content of the ItemsControl is grouped by the Type attribute.

형식의 각 그룹은 CollectionViewGroup합니다.Each group is of type CollectionViewGroup. GroupStyle HeaderTemplate 으로 표시 되도록 지정을 TextBlock 표시 하는 Name 각 그룹입니다.The GroupStyle HeaderTemplate is specified so that it appears as a TextBlock that displays the Name of each the group. 이 경우에 Name 중 하나는 Work 또는 Home합니다.In this case, the Name is either Work or Home.

<Window x:Class="GroupingSample.Window1"
    Title="Grouping Sample"
    Width="220" Height="550">

      <XmlDataProvider x:Key="myTasks" XPath="Tasks/Task">
          <Tasks xmlns="">
            <Task Name="Groceries" Priority="2" Type="Home">
              <Description>Pick up Groceries and Detergent</Description>
            <Task Name="Laundry" Priority="2" Type="Home">
              <Description>Do Laundry</Description>
            <Task Name="Email" Priority="1" Type="Work">
              <Description>Email Clients</Description>
            <Task Name="Clean" Priority="3" Type="Work">
              <Description>Clean my office</Description>
            <Task Name="Dinner" Priority="1" Type="Home">
              <Description>Get ready for family reunion</Description>
            <Task Name="Proposals" Priority="2" Type="Work">
              <Description>Review new budget proposals</Description>

    <TextBlock Margin="12,5,5,0" FontSize="20" Text="My Task List"/>
    <CheckBox Margin="10,5,5,10" Checked="AddGrouping"
              Unchecked="RemoveGrouping">Group by task type</CheckBox>
    <ItemsControl Margin="10" Name="myItemsControl"
                  ItemsSource="{Binding Source={StaticResource myTasks}}">
            <Style TargetType="TextBlock">
              <Setter Property="FontSize" Value="18"/>
              <Setter Property="HorizontalAlignment" Value="Center"/>
            <Ellipse Fill="Silver"/>
              <TextBlock Margin="3,3,3,0"
                         Text="{Binding XPath=@Name}"/>
              <TextBlock Margin="3,0,3,7"
                         Text="{Binding XPath=@Priority}"/>
          <Setter Property="Control.Width" Value="100"/>
          <Setter Property="Control.Margin" Value="5"/>
              <TextBlock FontWeight="Bold" FontSize="15"
                         Text="{Binding Path=Name}"/>
using System;
using System.Windows;
using System.Windows.Data;

namespace GroupingSample
    public partial class Window1 : System.Windows.Window

        public Window1()

        CollectionView myView;
        private void AddGrouping(object sender, RoutedEventArgs e)
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);
            if (myView.CanGroup == true)
                PropertyGroupDescription groupDescription
                    = new PropertyGroupDescription("@Type");

        private void RemoveGrouping(object sender, RoutedEventArgs e)
            myView = (CollectionView)CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource);

Imports System.Windows
Imports System.Windows.Data

Namespace GroupingSample
    Partial Public Class Window1
        Inherits System.Windows.Window

        Public Sub New()
        End Sub

        Private myView As CollectionView
        Private Sub AddGrouping(ByVal sender As Object, ByVal e As RoutedEventArgs)
            myView = CType(CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource), CollectionView)
            If myView.CanGroup = True Then
                Dim groupDescription As New PropertyGroupDescription("@Type")
            End If
        End Sub

        Private Sub RemoveGrouping(ByVal sender As Object, ByVal e As RoutedEventArgs)
            myView = CType(CollectionViewSource.GetDefaultView(myItemsControl.ItemsSource), CollectionView)
        End Sub
    End Class
End Namespace

다음 예제에서는 사용 하는 방법의 HeaderTemplate 속성:The following example shows how to use the HeaderTemplate property:

<ListBox Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
    ItemsSource="{Binding Source={StaticResource listingDataView}}">
          HeaderTemplate="{StaticResource groupingHeaderTemplate}"

다음은 정의 된 groupingHeaderTemplate DataTemplate:The following is the definition of the groupingHeaderTemplateDataTemplate:

<DataTemplate x:Key="groupingHeaderTemplate">
    <TextBlock Text="{Binding Path=Name}"
               Foreground="Navy" FontWeight="Bold" FontSize="12"/>

전체 샘플을 참조 하세요 데이터 바인딩 데모합니다.For the complete sample, see Data Binding Demo.

적용 대상

추가 정보