GroupStyle 類別

定義

描述如何在集合中顯示群組專案,例如 來自 GroupItems 的集合。

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class GroupStyle : INotifyPropertyChanged
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class GroupStyle : INotifyPropertyChanged
Public Class GroupStyle
Implements INotifyPropertyChanged
<GroupStyle />
繼承
Object IInspectable GroupStyle
屬性
實作

範例

在這裡,GroupStyle 會套用至包含群組數據的 GridView 控制件。 如需詳細資訊,以及查看完整的範例程式代碼,請參閱 如何在清單或方格中將專案分組

<GridView ItemsSource="{Binding Source={StaticResource cvsProjects}}" 
  Margin="0,120,0,0" MaxHeight="500" Grid.Column="1">
    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="20">
                <TextBlock Text="{Binding Name}" FontWeight="Bold" 
                           Style="{StaticResource BaseTextBlockStyle}"/>
                <TextBlock Text="{Binding DueDate}" TextWrapping="NoWrap" 
                           Style="{StaticResource BodyTextBlockStyle}" />
                <CheckBox Content="Complete" IsChecked="{Binding Complete}" 
                          IsEnabled="False"/>
            </StackPanel>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="3"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    <GridView.GroupStyle>
        <GroupStyle HidesIfEmpty="True">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid Background="LightGray" Margin="0">
                        <TextBlock Text='{Binding Name}' 
                                   Foreground="Black" Margin="30"
                                   Style="{StaticResource HeaderTextBlockStyle}"/>
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>

        </GroupStyle>
    </GridView.GroupStyle>
</GridView>

備註

GroupStyle 通常會定義在 Extensible Application Markup Language (XAML) ,然後設定為 ItemsControl.GroupStyle 屬性的值,以定義群組的視覺外觀。

建構函式

GroupStyle()

初始化 GroupStyle 類別的新實例。

屬性

ContainerStyle

注意

在 Windows 8.1 之後,可能會變更或無法使用 ContainerStyle 版本,且不支援 ItemsControl.GroupStyle

取得或設定套用至針對每個項目產生的 GroupItem 的樣式。

ContainerStyleSelector

注意

在 Windows 8.1 之後,ContainerStyleSelector 可能會改變或無法使用,而且 ItemsControl.GroupStyle 不支援。

取得或設定自定義 StyleSelector 邏輯類別的參考。 此屬性所參考的 StyleSelector 會傳回套用至每個產生的 GroupItem 的樣式。

HeaderContainerStyle

取得或設定套用至每個項目的標頭的樣式。

HeaderTemplate

取得或設定用來顯示群組標頭的範本。

HeaderTemplateSelector

取得或設定自定義 DataTemplateSelector 邏輯類別的參考。 DataTemplateSelector 會傳回不同的 DataTemplate 值,以用於群組專案內容的標頭區域。

HidesIfEmpty

取得或設定值,這個值表示是否應該顯示對應到空群組的項目。

Panel

取得或設定範本,這個範本會建立用來配置項目的面板。

事件

PropertyChanged

當屬性值變更時發生。

適用於

另請參閱