CurrentChangingEventArgs CurrentChangingEventArgs CurrentChangingEventArgs Class

Definition

Provides data for the CurrentChanging event.

public class CurrentChangingEventArgs : ICurrentChangingEventArgspublic class CurrentChangingEventArgs : ICurrentChangingEventArgsPublic Class CurrentChangingEventArgs Implements ICurrentChangingEventArgs
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The CurrentChanging event occurs when the CurrentItem property value changes in an ICollectionView implementation. The ICollectionView implementation uses the CurrentChangingEventArgs constructor to specify whether you can cancel the CurrentItem change in a CurrentChanging event handler. If the IsCancelable property value is true, you can cancel the CurrentItem change by setting the Cancel property to true. Otherwise, you cannot cancel the CurrentItem change.

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;
    }
}

Constructors

CurrentChangingEventArgs() CurrentChangingEventArgs() CurrentChangingEventArgs()

Initializes a new instance of the CurrentChangingEventArgs class.

public CurrentChangingEventArgs()public CurrentChangingEventArgs()Public Sub New()
Attributes

CurrentChangingEventArgs(Boolean) CurrentChangingEventArgs(Boolean) CurrentChangingEventArgs(Boolean)

Initializes a new instance of the CurrentChangingEventArgs class.

public CurrentChangingEventArgs(Boolean isCancelable)public CurrentChangingEventArgs(Boolean isCancelable)Public Sub New(isCancelable As Boolean)
Parameters
isCancelable
System.Boolean System.Boolean System.Boolean

true to disable the ability to cancel a CurrentItem change; false to enable cancellation.

Attributes

Properties

Cancel Cancel Cancel

Gets or sets a value that indicates whether the CurrentItem change should be canceled.

public bool Cancel { get; set; }public bool Cancel { get; set; }Public ReadWrite Property Cancel As bool
Value
bool bool bool

true if the event should be canceled; otherwise, false. The default is false.

Attributes

Remarks

If the IsCancelable property value is false, setting the Cancel property to true will throw an InvalidOperationException.

IsCancelable IsCancelable IsCancelable

Gets a value that indicates whether the CurrentItem change can be canceled.

public bool IsCancelable { get; }public bool IsCancelable { get; }Public ReadOnly Property IsCancelable As bool
Value
bool bool bool

true if the event can be canceled; false if the event cannot be canceled.

Attributes

Remarks

If the IsCancelable property value is false, setting the Cancel property to true will throw an InvalidOperationException.

See Also