다음을 통해 공유


ItemsControl.GroupStyle 속성

정의

각 그룹 수준의 모양을 정의하는 GroupStyle 개체의 컬렉션을 가져옵니다.

public:
 property System::Collections::ObjectModel::ObservableCollection<System::Windows::Controls::GroupStyle ^> ^ GroupStyle { System::Collections::ObjectModel::ObservableCollection<System::Windows::Controls::GroupStyle ^> ^ get(); };
public System.Collections.ObjectModel.ObservableCollection<System.Windows.Controls.GroupStyle> GroupStyle { get; }
member this.GroupStyle : System.Collections.ObjectModel.ObservableCollection<System.Windows.Controls.GroupStyle>
Public ReadOnly Property GroupStyle As ObservableCollection(Of GroupStyle)

속성 값

각 그룹 수준의 모양을 정의하는 GroupStyle 개체의 컬렉션입니다.

예제

다음 예제에서는 XmlDataProvider 바인딩된 ItemsControl 그룹화 추가 및 제거 논리를 포함하는 코드 숨김 콘텐츠를 보여 줍니다. 확인란을 선택하면 ItemsControl 내용이 Type 특성별로 그룹화됩니다.

각 그룹은 CollectionViewGroup형식입니다. GroupStyle HeaderTemplate 각 그룹의 Name 표시하는 TextBlock 표시되도록 지정됩니다. 이 경우 NameWork 또는 Home.

<Window x:Class="GroupingSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Grouping Sample"
    Width="220" Height="550">
  <StackPanel>

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

    <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}}">
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <DataTemplate.Resources>
            <Style TargetType="TextBlock">
              <Setter Property="FontSize" Value="18"/>
              <Setter Property="HorizontalAlignment" Value="Center"/>
            </Style>
          </DataTemplate.Resources>
          <Grid>
            <Ellipse Fill="Silver"/>
            <StackPanel>
              <TextBlock Margin="3,3,3,0"
                         Text="{Binding XPath=@Name}"/>
              <TextBlock Margin="3,0,3,7"
                         Text="{Binding XPath=@Priority}"/>
            </StackPanel>
          </Grid>
        </DataTemplate>
      </ItemsControl.ItemTemplate>
      <ItemsControl.ItemContainerStyle>
        <Style>
          <Setter Property="Control.Width" Value="100"/>
          <Setter Property="Control.Margin" Value="5"/>
        </Style>
      </ItemsControl.ItemContainerStyle>
      <ItemsControl.GroupStyle>
        <GroupStyle>
          <GroupStyle.HeaderTemplate>
            <DataTemplate>
              <TextBlock FontWeight="Bold" FontSize="15"
                         Text="{Binding Path=Name}"/>
            </DataTemplate>
          </GroupStyle.HeaderTemplate>
        </GroupStyle>
      </ItemsControl.GroupStyle>
    </ItemsControl>
  </StackPanel>
</Window>
using System;
using System.Windows;
using System.Windows.Data;

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

        public Window1()
        {
            InitializeComponent();
        }

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

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

Imports System.Windows
Imports System.Windows.Data

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

        Public Sub New()
            InitializeComponent()
        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")
                myView.GroupDescriptions.Add(groupDescription)
            Else
                Return
            End If
        End Sub

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

설명

인덱스 0의 항목은 최상위 그룹을 설명하고 인덱스 1의 항목은 다음 수준을 설명합니다. 컬렉션의 항목보다 그룹화 수준이 더 많은 경우 마지막 항목이 추가 수준에 사용됩니다.

XAML 속성 요소 사용

<object>
  <object.GroupStyle>
    OneOrMoreGroupStyleObjects
  </object.GroupStyle>
</object>

XAML 값

OneOrMoreGroupStyleObjects 하나 이상의 개체를 .

적용 대상

추가 정보