ICollectionView
ICollectionView
ICollectionView
ICollectionView
Interface
Definition
Enables collections to support current record management, grouping, and incremental loading (data virtualization).
public : interface ICollectionViewpublic interface ICollectionViewPublic Interface ICollectionView// This API is not available in Javascript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
ICollectionView is an interface used to represent a collection. It serves to maintain currency for properties like item selection.
To implement custom behavior for selection currency in your data source, your data source should implement ICollectionViewFactory instead of implementing ICollectionView directly. You can set the CollectionViewSource.Source property to an ICollectionViewFactory, but if you set it to an ICollectionView, it will throw an exception.
The CollectionGroups property is of type IObservableVector;, but these objects should implement ICollectionViewGroup.
Interface inheritance
ICollectionView inherits IObservableVector, IVector and IIterable . Types that implement ICollectionView also implement the interface members of IObservableVector, and either IVector and IIterable for C++ usage or IListand IEnumerable for Microsoft .NET usage.
Properties
CollectionGroups CollectionGroups CollectionGroups CollectionGroups
Returns any collection groups that are associated with the view.
public : IObservableVector<object> CollectionGroups { get; }public IObservableVector<object> CollectionGroups { get; }Public ReadOnly Property CollectionGroups As IObservableVector<object>// This API is not available in Javascript.
- Value
- IObservableVector<PlatForm::Object> IObservableVector<object> IObservableVector<object> IObservableVector<object>
A vector collection of possible views.
Remarks
The CollectionGroups property is of type IObservableVector;, but these objects should implement ICollectionViewGroup.
CurrentItem CurrentItem CurrentItem CurrentItem
Gets the current item in the view.
public : PlatForm::Object CurrentItem { get; }public object CurrentItem { get; }Public ReadOnly Property CurrentItem As object// This API is not available in Javascript.
- Value
- PlatForm::Object object object object
The current item in the view or null if there is no current item.
CurrentPosition CurrentPosition CurrentPosition CurrentPosition
Gets the ordinal position of the CurrentItem within the view.
public : int CurrentPosition { get; }public int CurrentPosition { get; }Public ReadOnly Property CurrentPosition As int// This API is not available in Javascript.
- Value
- int int int int
The ordinal position of the CurrentItem within the view.
HasMoreItems HasMoreItems HasMoreItems HasMoreItems
Gets a sentinel value that supports incremental loading implementations. See also LoadMoreItemsAsync.
public : PlatForm::Boolean HasMoreItems { get; }public bool HasMoreItems { get; }Public ReadOnly Property HasMoreItems As bool// This API is not available in Javascript.
- Value
- PlatForm::Boolean bool bool bool
true if additional unloaded items remain in the view; otherwise, false.
IsCurrentAfterLast IsCurrentAfterLast IsCurrentAfterLast IsCurrentAfterLast
Gets a value that indicates whether the CurrentItem of the view is beyond the end of the collection.
public : PlatForm::Boolean IsCurrentAfterLast { get; }public bool IsCurrentAfterLast { get; }Public ReadOnly Property IsCurrentAfterLast As bool// This API is not available in Javascript.
- Value
- PlatForm::Boolean bool bool bool
true if the CurrentItem of the view is beyond the end of the collection; otherwise, false.
IsCurrentBeforeFirst IsCurrentBeforeFirst IsCurrentBeforeFirst IsCurrentBeforeFirst
Gets a value that indicates whether the CurrentItem of the view is beyond the beginning of the collection.
public : PlatForm::Boolean IsCurrentBeforeFirst { get; }public bool IsCurrentBeforeFirst { get; }Public ReadOnly Property IsCurrentBeforeFirst As bool// This API is not available in Javascript.
- Value
- PlatForm::Boolean bool bool bool
true if the CurrentItem of the view is beyond the beginning of the collection; otherwise, false.
Methods
LoadMoreItemsAsync(UInt32) LoadMoreItemsAsync(UInt32) LoadMoreItemsAsync(UInt32) LoadMoreItemsAsync(UInt32)
Initializes incremental loading from the view.
public : IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(unsigned int count)public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(UInt32 count)Public Function LoadMoreItemsAsync(count As UInt32) As IAsyncOperation( Of LoadMoreItemsResult )// This API is not available in Javascript.
- count
- unsigned int UInt32 UInt32 UInt32
The number of items to load.
The wrapped results of the load operation.
MoveCurrentTo(Object) MoveCurrentTo(Object) MoveCurrentTo(Object) MoveCurrentTo(Object)
Sets the specified item to be the CurrentItem in the view.
public : PlatForm::Boolean MoveCurrentTo(PlatForm::Object item)public bool MoveCurrentTo(Object item)Public Function MoveCurrentTo(item As Object) As bool// This API is not available in Javascript.
- item
- PlatForm::Object Object Object Object
The item to set as the CurrentItem.
true if the resulting CurrentItem is within the view; otherwise, false.
MoveCurrentToFirst() MoveCurrentToFirst() MoveCurrentToFirst() MoveCurrentToFirst()
Sets the first item in the view as the CurrentItem.
public : PlatForm::Boolean MoveCurrentToFirst()public bool MoveCurrentToFirst()Public Function MoveCurrentToFirst() As bool// This API is not available in Javascript.
true if the resulting CurrentItem is an item within the view; otherwise, false.
MoveCurrentToLast() MoveCurrentToLast() MoveCurrentToLast() MoveCurrentToLast()
Sets the last item in the view as the CurrentItem.
public : PlatForm::Boolean MoveCurrentToLast()public bool MoveCurrentToLast()Public Function MoveCurrentToLast() As bool// This API is not available in Javascript.
true if the resulting CurrentItem is an item within the view; otherwise, false.
MoveCurrentToNext() MoveCurrentToNext() MoveCurrentToNext() MoveCurrentToNext()
Sets the item after the CurrentItem in the view as the CurrentItem.
public : PlatForm::Boolean MoveCurrentToNext()public bool MoveCurrentToNext()Public Function MoveCurrentToNext() As bool// This API is not available in Javascript.
true if the resulting CurrentItem is an item within the view; otherwise, false.
MoveCurrentToPosition(Int32) MoveCurrentToPosition(Int32) MoveCurrentToPosition(Int32) MoveCurrentToPosition(Int32)
Sets the item at the specified index to be the CurrentItem in the view.
public : PlatForm::Boolean MoveCurrentToPosition(int index)public bool MoveCurrentToPosition(Int32 index)Public Function MoveCurrentToPosition(index As Int32) As bool// This API is not available in Javascript.
- index
- int Int32 Int32 Int32
The index of the item to move to.
true if the resulting CurrentItem is an item within the view; otherwise, false.
MoveCurrentToPrevious() MoveCurrentToPrevious() MoveCurrentToPrevious() MoveCurrentToPrevious()
Sets the item before the CurrentItem in the view as the CurrentItem.
public : PlatForm::Boolean MoveCurrentToPrevious()public bool MoveCurrentToPrevious()Public Function MoveCurrentToPrevious() As bool// This API is not available in Javascript.
true if the resulting CurrentItem is an item within the view; otherwise, false.
Events
CurrentChanged CurrentChanged CurrentChanged CurrentChanged
When implementing this interface, fire this event after the current item has been changed.
public : abstract event EventHandler CurrentChanged<object>public abstract event EventHandler CurrentChanged<object>Public MustInherit Event CurrentChanged<object>// This API is not available in Javascript.
Remarks
Don't implement this interface for Microsoft .NET. See Remarks in ICollectionView.
CurrentChanging CurrentChanging CurrentChanging CurrentChanging
When implementing this interface, fire this event before changing the current item. The event handler can cancel this event.
public : abstract event CurrentChangingEventHandler CurrentChangingpublic abstract event CurrentChangingEventHandler CurrentChangingPublic MustInherit Event CurrentChanging// This API is not available in Javascript.
Examples
The following code example demonstrates how to handle the CurrentChanging event. In this example, the XAML shows the content of a page with a GridView bound to a CollectionViewSource. The code-behind shows the CollectionViewSource initialization, which includes setting its Source and retrieving its View in order to attach the CurrentChanging event handler.
<Page.Resources>
<CollectionViewSource x:Name="cvs" />
<DataTemplate x:Key="myDataTemplate">
<Border Background="#FF939598" Width="200" Height="200">
<TextBlock Text="{Binding Path=Name}" />
</Border>
</DataTemplate>
</Page.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
<GridView x:Name="PicturesGrid"
SelectionMode="Single" CanReorderItems="False" CanDragItems="False"
ItemsSource="{Binding Source={StaticResource cvs}}"
ItemTemplate="{StaticResource myDataTemplate}" >
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid VerticalChildrenAlignment="Top"
HorizontalChildrenAlignment="Left" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</Grid>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var library = Windows.Storage.KnownFolders.PicturesLibrary;
var queryOptions = new Windows.Storage.Search.QueryOptions();
queryOptions.FolderDepth = Windows.Storage.Search.FolderDepth.Deep;
queryOptions.IndexerOption =
Windows.Storage.Search.IndexerOption.UseIndexerWhenAvailable;
var fileQuery = library.CreateFileQueryWithOptions(queryOptions);
var fif = new Windows.Storage.BulkAccess.FileInformationFactory(
fileQuery,
Windows.Storage.FileProperties.ThumbnailMode.PicturesView, 190,
Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale,
false);
var dataSource = fif.GetVirtualizedFilesVector();
cvs.Source = dataSource;
cvs.View.CurrentChanging += View_CurrentChanging;
}
private void View_CurrentChanging(object sender, CurrentChangingEventArgs e)
{
Debug.WriteLine("Cancel = " + e.Cancel);
Debug.WriteLine("IsCancelable = " + e.IsCancelable);
if (e.IsCancelable == true)
{
// Cancel the change. The previously selected item remains selected.
e.Cancel = true;
}
}
Remarks
The CurrentChanging event occurs when the CurrentItem property value is changing. The CurrentChangingEventArgs parameter passed to the event handler specifies information about the change. If IsCancelable is true, the event handler can cancel the change by setting Cancel to true. If the change is canceled, CurrentItem is not changed. Setting Cancel to true when IsCancelable is false throws an exception.
Classes that implement this interface should fire the CurrentChanging event, set IsCancelable as appropriate, and then check the Cancel property before changing the CurrentItem and firing the CurrentChanged event.