GroupStyle Class

Definition

Define cómo quiere que el grupo busque en cada nivel.Defines how you want the group to look at each level.

public ref class GroupStyle : System::ComponentModel::INotifyPropertyChanged
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public class GroupStyle : System.ComponentModel.INotifyPropertyChanged
type GroupStyle = class
    interface INotifyPropertyChanged
Public Class GroupStyle
Implements INotifyPropertyChanged
Inheritance
GroupStyle
Attributes
Implements

Examples

En los siguientes ejemplos se muestra un ItemsControl que está enlazado a un XmlDataProvider y el contenido de código subyacente que contiene la lógica para agregar y quitar la agrupación.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. Cuando se activa la casilla, el contenido de la ItemsControl se agrupa por el atributo Type.When the check box is checked, the content of the ItemsControl is grouped by the Type attribute.

Cada grupo es de tipo CollectionViewGroup.Each group is of type CollectionViewGroup. Se especifica el HeaderTemplate de GroupStyle para que aparezca como un TextBlock que muestra el Name de cada grupo.The GroupStyle HeaderTemplate is specified so that it appears as a TextBlock that displays the Name of each the group. En este caso, el Name es Work o Home.In this case, the Name is either Work or 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

Constructors

GroupStyle()

Inicializa una nueva instancia de la clase GroupStyle.Initializes a new instance of the GroupStyle class.

Fields

DefaultGroupPanel

Identifica el ItemsPanelTemplate predeterminado que crea el panel que se utiliza para diseñar los elementos.Identifies the default ItemsPanelTemplate that creates the panel used to layout the items.

Properties

AlternationCount

Obtiene o establece el número de objetos GroupItem alternos.Gets or sets the number of alternating GroupItem objects.

ContainerStyle

Obtiene o establece el estilo que se aplica al elemento GroupItem generado para cada elemento.Gets or sets the style that is applied to the GroupItem generated for each item.

ContainerStyleSelector

Permite que el autor de la aplicación proporcione una lógica de selección personalizada para aplicar un estilo a cada GroupItem generado.Enables the application writer to provide custom selection logic for a style to apply to each generated GroupItem.

Default

Obtiene el estilo predeterminado del grupo.Gets the default style of the group.

HeaderStringFormat

Obtiene o establece una cadena compuesta que especifica cómo se aplica formato al encabezado si se muestra como una cadena.Gets or sets a composite string that specifies how to format the header if it is displayed as a string.

HeaderTemplate

Obtiene o establece la plantilla que se usa para mostrar el encabezado de grupo.Gets or sets the template that is used to display the group header.

HeaderTemplateSelector

Permite que el autor de la aplicación proporcione una lógica de selección personalizada para una plantilla que se utiliza con el fin de mostrar el encabezado de grupo.Enables the application writer to provide custom selection logic for a template that is used to display the group header.

HidesIfEmpty

Obtiene o establece un valor que indica si deben mostrarse los elementos correspondientes a grupos vacíos.Gets or sets a value that indicates whether items corresponding to empty groups should be displayed.

Panel

Obtiene o establece una plantilla que crear el panel que se utiliza para diseñar los elementos.Gets or sets a template that creates the panel used to layout the items.

Methods

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(PropertyChangedEventArgs)

Genera el evento PropertyChanged con los argumentos proporcionados.Raises the PropertyChanged event using the provided arguments.

ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Events

PropertyChanged

Se produce cuando un valor de propiedad cambia.Occurs when a property value changes.

Explicit Interface Implementations

INotifyPropertyChanged.PropertyChanged

Se produce cuando un valor de propiedad cambia.Occurs when a property value changes.

Applies to

See also