Share via


CurrentChangingEventArgs Classe

Definizione

Fornisce i dati per l'evento CurrentChanging .

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 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(Windows.Foundation.UniversalApiContract), 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
Ereditarietà
Object IInspectable CurrentChangingEventArgs
Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 10 (è stato introdotto in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v1.0)

Esempio

Nell'esempio di codice seguente viene illustrato come gestire l'evento CurrentChanging . In questo esempio, il codice XAML mostra il contenuto di una pagina con un oggetto GridView associato a un Oggetto CollectionViewSource. Il code-behind mostra l'inizializzazione CollectionViewSource , che include l'impostazione dell'origine e il recupero della visualizzazione per collegare il gestore eventi 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;
    }
}

Commenti

L'evento CurrentChanging si verifica quando il valore della proprietà CurrentItem cambia in un'implementazione di ICollectionView . L'implementazione di ICollectionView usa il costruttore CurrentChangingEventArgs per specificare se è possibile annullare la modifica CurrentItem in un gestore eventi CurrentChanging . Se il valore della proprietà IsCancelable è true, è possibile annullare la modifica CurrentItem impostando la proprietà Cancel su true. In caso contrario, non è possibile annullare la modifica CurrentItem .

Costruttori

CurrentChangingEventArgs()

Inizializza una nuova istanza della classe CurrentChangingEventArgs .

CurrentChangingEventArgs(Boolean)

Inizializza una nuova istanza della classe CurrentChangingEventArgs .

Proprietà

Cancel

Ottiene o imposta un valore che indica se la modifica CurrentItem deve essere annullata.

IsCancelable

Ottiene un valore che indica se la modifica CurrentItem può essere annullata.

Si applica a

Vedi anche