CurrentChangingEventArgs CurrentChangingEventArgs CurrentChangingEventArgs Class

Provides data for the CurrentChanging event.

Syntax

Declaration

public class CurrentChangingEventArgspublic class CurrentChangingEventArgsPublic Class CurrentChangingEventArgs

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 summary

Initializes a new instance of the CurrentChangingEventArgs class.

Initializes a new instance of the CurrentChangingEventArgs class.

Properties summary

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

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

Constructors

  • CurrentChangingEventArgs()
    CurrentChangingEventArgs()
    CurrentChangingEventArgs()
    CurrentChangingEventArgs()

    Initializes a new instance of the CurrentChangingEventArgs class.

    public CurrentChangingEventArgs()public New()Public Sub New()public CurrentChangingEventArgs()
  • CurrentChangingEventArgs(Boolean)
    CurrentChangingEventArgs(Boolean)
    CurrentChangingEventArgs(Boolean)
    CurrentChangingEventArgs(Boolean)

    Initializes a new instance of the CurrentChangingEventArgs class.

    public CurrentChangingEventArgs(Boolean isCancelable)public New(Boolean isCancelable)Public Sub New(isCancelable As Boolean)public CurrentChangingEventArgs(Boolean isCancelable)

    Parameters

    • isCancelable
      System.Boolean
      System.Boolean
      System.Boolean

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

Properties

  • Cancel
    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 boolpublic bool Cancel { get; set; }

    Property Value

    • bool
      bool
      bool

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

    Remarks

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

  • IsCancelable
    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 boolpublic bool IsCancelable { get; }

    Property Value

    • bool
      bool
      bool

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

    Remarks

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Data.dll