Bagikan melalui


CurrentChangingEventArgs Kelas

Definisi

Menyediakan data untuk peristiwa CurrentChanging .

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class CurrentChangingEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class CurrentChangingEventArgs
Public Class CurrentChangingEventArgs
Warisan
Object IInspectable CurrentChangingEventArgs
Atribut

Contoh

Contoh kode berikut menunjukkan cara menangani peristiwa CurrentChanging . Dalam contoh ini, XAML menunjukkan konten halaman dengan GridView yang terikat ke CollectionViewSource. Kode di belakang menunjukkan inisialisasi CollectionViewSource , yang mencakup pengaturan Sumbernya dan mengambil Tampilannya untuk melampirkan penanganan aktivitas 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;
    }
}

Keterangan

Peristiwa CurrentChanging terjadi ketika nilai properti CurrentItem berubah dalam implementasi ICollectionView . Implementasi ICollectionView menggunakan konstruktor CurrentChangingEventArgs untuk menentukan apakah Anda dapat membatalkan perubahan CurrentItem dalam penanganan aktivitas CurrentChanging . Jika nilai properti IsCancelablebenar, Anda dapat membatalkan perubahan CurrentItem dengan mengatur properti Batalkan ke true. Jika tidak, Anda tidak dapat membatalkan perubahan CurrentItem .

Konstruktor

CurrentChangingEventArgs()

Menginisialisasi instans baru kelas CurrentChangingEventArgs .

CurrentChangingEventArgs(Boolean)

Menginisialisasi instans baru kelas CurrentChangingEventArgs .

Properti

Cancel

Mendapatkan atau menetapkan nilai yang menunjukkan apakah perubahan CurrentItem harus dibatalkan.

IsCancelable

Mendapatkan nilai yang menunjukkan apakah perubahan CurrentItem dapat dibatalkan.

Berlaku untuk

Lihat juga