GroupStyle 類別

定義

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

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 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(Windows.Foundation.UniversalApiContract), 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
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

在這裡,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

當屬性值變更時發生。

適用於

另請參閱