GroupStyle Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menentukan bagaimana Anda ingin grup melihat setiap tingkat.
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
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
type GroupStyle = class
interface INotifyPropertyChanged
Public Class GroupStyle
Implements INotifyPropertyChanged
- Warisan
-
GroupStyle
- Atribut
- Penerapan
Contoh
Contoh berikut menunjukkan ItemsControl yang terikat ke XmlDataProvider konten dan di belakang kode yang berisi logika untuk menambahkan dan menghapus pengelompokan. Saat kotak centang dicentang, konten ItemsControl dikelompokkan menurut Type
atribut .
Setiap grup berjenis CollectionViewGroup. GroupStyleHeaderTemplate ditentukan sehingga muncul sebagai TextBlock yang menampilkan Name dari setiap grup. Dalam hal ini, Name adalah Work
atau 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
Konstruktor
GroupStyle() |
Menginisialisasi instans baru kelas GroupStyle. |
Bidang
DefaultGroupPanel |
Mengidentifikasi default ItemsPanelTemplate yang membuat panel yang digunakan untuk tata letak item. |
Properti
AlternationCount |
Mendapatkan atau mengatur jumlah objek alternatif GroupItem . |
ContainerStyle |
Mendapatkan atau mengatur gaya yang diterapkan ke yang GroupItem dihasilkan untuk setiap item. |
ContainerStyleSelector |
Memungkinkan penulis aplikasi untuk menyediakan logika pemilihan kustom untuk gaya yang akan diterapkan ke setiap yang dihasilkan GroupItem. |
Default |
Mendapatkan gaya default grup. |
HeaderStringFormat |
Mendapatkan atau mengatur string komposit yang menentukan cara memformat header jika ditampilkan sebagai string. |
HeaderTemplate |
Mendapatkan atau mengatur templat yang digunakan untuk menampilkan header grup. |
HeaderTemplateSelector |
Memungkinkan penulis aplikasi menyediakan logika pilihan kustom untuk templat yang digunakan untuk menampilkan header grup. |
HidesIfEmpty |
Mendapatkan atau mengatur nilai yang menunjukkan apakah item yang terkait dengan grup kosong harus ditampilkan. |
Panel |
Mendapatkan atau mengatur templat yang membuat panel yang digunakan untuk mengatur tata letak item. |
Metode
Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
GetType() |
Mendapatkan instans Type saat ini. (Diperoleh dari Object) |
MemberwiseClone() |
Membuat salinan dangkal dari yang saat ini Object. (Diperoleh dari Object) |
OnPropertyChanged(PropertyChangedEventArgs) |
Menaikkan PropertyChanged peristiwa menggunakan argumen yang disediakan. |
ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
Acara
PropertyChanged |
Terjadi saat nilai properti berubah. |
Implementasi Antarmuka Eksplisit
INotifyPropertyChanged.PropertyChanged |
Terjadi saat nilai properti berubah. |
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk