CollectionViewSource.IsSourceGrouped 屬性

定義

取得或設定值,這個值表示源數據是否已分組。

public:
 property bool IsSourceGrouped { bool get(); void set(bool value); };
bool IsSourceGrouped();

void IsSourceGrouped(bool value);
public bool IsSourceGrouped { get; set; }
var boolean = collectionViewSource.isSourceGrouped;
collectionViewSource.isSourceGrouped = boolean;
Public Property IsSourceGrouped As Boolean
<CollectionViewSource IsSourceGrouped="bool" .../>

屬性值

Boolean

bool

如果數據已分組,則為 true。 如果數據未分組,則為 false

範例

下列程式代碼範例示範如何將 ListBox 控件系結至群組 LINQ 查詢的結果。 在此範例中,小組的集合會依城市分組,並以城市名稱顯示為群組標頭。 如需完整的程式代碼清單,請參閱 XAML 資料系結範例。 如需群組的其他範例程序代碼,請參閱 Grouped GridView 範例

<Grid>

  <Grid.Resources>
    <CollectionViewSource x:Name="groupInfoCVS" IsSourceGrouped="true"/>
  </Grid.Resources>

  <ListBox x:Name="lbGroupInfoCVS" 
    ItemsSource="{Binding Source={StaticResource groupInfoCVS}}">

    <ListBox.GroupStyle>
      <GroupStyle>
        <GroupStyle.HeaderTemplate>
          <DataTemplate>

            <TextBlock Text="{Binding Key}"/>

          </DataTemplate>
        </GroupStyle.HeaderTemplate>
      </GroupStyle>
    </ListBox.GroupStyle>

    <ListBox.ItemTemplate>
      <DataTemplate>

        <Border Background="{Binding Color}" 
          Width="200" CornerRadius="10" HorizontalAlignment="Left">

          <TextBlock Text="{Binding Name}" 
            Style="{StaticResource DescriptionTextStyle}" 
            HorizontalAlignment="Center" FontWeight="Bold"/>

        </Border>
      </DataTemplate>
    </ListBox.ItemTemplate>

  </ListBox>

</Grid>
Teams teams = new Teams();
var result = 
    from t in teams 
    group t by t.City into g 
    orderby g.Key 
    select g;
groupInfoCVS.Source = result;

適用於

另請參閱