Provides a proxy over collection classes to enable currency and grouping support.
Inheritance
- Object
- DependencyObject
- CollectionViewSource
Syntax
<CollectionViewSource .../>
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.UI.Xaml.Data.ICollectionViewSourceStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The CollectionViewSource class has these types of members:
Constructors
The CollectionViewSource class has these constructors.
| Constructor | Description |
|---|---|
| CollectionViewSource | Initializes a new instance of the CollectionViewSource class. |
Methods
The CollectionViewSource class has these methods. It also inherits methods from the Object class.
| Method | Description |
|---|---|
| ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject) |
| GetAnimationBaseValue | Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject) |
| GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject) |
| ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject) |
| SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject) |
Properties
The CollectionViewSource class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject) | |
| Read/write | Gets or sets a value that indicates whether source data is grouped. | |
| Read-only | Identifies the IsSourceGrouped dependency property. | |
| Read/write | Gets or sets the property path to follow from the top level item to find groups within the CollectionViewSource. | |
| Read-only | Identifies the ItemsPath dependency property. | |
| Read/write | Gets or sets the collection object from which to create this view. | |
| Read-only | Identifies the Source dependency property. | |
| Read-only | Gets the view object that is currently associated with this instance of CollectionViewSource. | |
| Read-only | Identifies the View dependency property. |
Remarks
You can also bind to instances of the CollectionViewSource class in order to display collections of collections and to keep track of the current item in multiple views. You typically define a CollectionViewSource as a XAML resource and bind to it using the StaticResource markup extension. You can then set its Source property in code-behind to a supported collection type.
Any controls that you bind to the same CollectionViewSource will always have the same current item. You can access the current item programmatically through the ICollectionView.CurrentItem property of the CollectionViewSource.View property value.
If the items in the collection are collections themselves, or are objects that contain collections, you can display the collections as groups within the larger collection. To do this, set the IsSourceGrouped property to true. If the items contain collections but are not collections themselves, you must also set the ItemsPath property to the name of the collection property.
Note Setting the Source property to another CollectionViewSource instance is not supported.
Examples
The following code example demonstrates how to bind a ListBox control to the results of a grouping LINQ query. In this example, a collection of teams is grouped by city and displayed with the city name as the group headers. For the complete code listing, see the XAML data binding sample. For additional example code on grouping, see the XAML GridView grouping and SemanticZoom sample.
<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;
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
- Binding
- Data binding overview
- XAML data binding sample
- XAML GridView grouping and SemanticZoom sample
Build date: 12/4/2012