GroupStyle GroupStyle GroupStyle GroupStyle Class

Definición

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
Herencia
GroupStyleGroupStyleGroupStyleGroupStyle
Atributos
Implementaciones

Ejemplos

Los ejemplos siguientes muestran 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 está activada la casilla de verificación, el contenido de la ItemsControl se agrupa por el Type atributo.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. El GroupStyle HeaderTemplate se especifica para que aparezca como un TextBlock que muestra la 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 sea 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
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

Constructores

GroupStyle() GroupStyle() GroupStyle() GroupStyle()

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

Campos

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

Propiedades

AlternationCount AlternationCount AlternationCount AlternationCount

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

ContainerStyle ContainerStyle ContainerStyle 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 ContainerStyleSelector ContainerStyleSelector 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 Default Default Default

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

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

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

HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector 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 HidesIfEmpty HidesIfEmpty 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 Panel Panel 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.

Métodos

Equals(Object) Equals(Object) Equals(Object) 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() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs) OnPropertyChanged(PropertyChangedEventArgs)

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

ToString() ToString() ToString() ToString()

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

(Inherited from Object)

Eventos

PropertyChanged PropertyChanged PropertyChanged PropertyChanged

Tiene lugar cuando cambia un valor de propiedad.Occurs when a property value changes.

Implementaciones de interfaz explícitas

INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged INotifyPropertyChanged.PropertyChanged

Tiene lugar cuando cambia un valor de propiedad.Occurs when a property value changes.

Se aplica a

Consulte también: