CurrentChangingEventHandler 委托   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示可以处理 ICollectionView 实现的 CurrentChanging 事件的方法。
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(4085812664, 5023, 19918, 141, 201, 247, 241, 68, 77, 17, 133)]
class CurrentChangingEventHandler : MulticastDelegate[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(4085812664, 5023, 19918, 141, 201, 247, 241, 68, 77, 17, 133)]
public delegate void CurrentChangingEventHandler(object sender, CurrentChangingEventArgs e);Public Delegate Sub CurrentChangingEventHandler(sender As Object, e As CurrentChangingEventArgs)参数
- sender
- 
				
				Object
IInspectable 
事件源。
事件数据。
- 属性
Windows 要求
| 设备系列 | 
							Windows 10 (在 10.0.10240.0 中引入) | 
| API contract | 
							Windows.Foundation.UniversalApiContract (在 v1.0 中引入) | 
示例
下面的代码示例演示如何处理 CurrentChanging 事件。 在此示例中,XAML 显示具有 绑定到 CollectionViewSource 的 GridView 的页面的内容。 代码隐藏显示 CollectionViewSource 初始化,其中包括设置其 Source 和检索其 View 以附加 CurrentChanging 事件处理程序。
<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;
    }
}
注解
当 CurrentItem 属性值发生更改时,会发生 ICollectionView.CurrentChanging 事件。 传递给事件处理程序的 CurrentChangingEventArgs 参数指定有关更改的信息。
如果 IsCancelable 为 true,则事件处理程序可以通过将 Cancel 设置为 true 来取消更改。 如果取消更改, 则 CurrentItem 不会更改。 当 IsCancelable 为 false 时将 Cancel 设置为 true 将引发异常。