ICollectionView.CurrentChanging Evento

Definizione

Quando si implementa questa interfaccia, attiva questo evento prima di modificare l'elemento corrente. Il gestore eventi può annullare questo evento.

// Register
event_token CurrentChanging(CurrentChangingEventHandler const& handler) const;

// Revoke with event_token
void CurrentChanging(event_token const* cookie) const;

// Revoke with event_revoker
ICollectionView::CurrentChanging_revoker CurrentChanging(auto_revoke_t, CurrentChangingEventHandler const& handler) const;
event CurrentChangingEventHandler CurrentChanging;
function onCurrentChanging(eventArgs) { /* Your code */ }
iCollectionView.addEventListener("currentchanging", onCurrentChanging);
iCollectionView.removeEventListener("currentchanging", onCurrentChanging);
- or -
iCollectionView.oncurrentchanging = onCurrentChanging;
Event CurrentChanging As CurrentChangingEventHandler 

Tipo evento

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 viene modificato il valore della proprietà CurrentItem . Il parametro CurrentChangingEventArgs passato al gestore eventi specifica informazioni sulla modifica. Se IsCancelable è true, il gestore eventi può annullare la modifica impostando Annulla su true. Se la modifica viene annullata, CurrentItem non viene modificata. L'impostazione Annulla su true quando IsCancelable è false genera un'eccezione.

Le classi che implementano questa interfaccia devono generare l'evento CurrentChanging, impostare IsCancelable come appropriato e quindi controllare la proprietà Cancel prima di modificare CurrentItem e attivare l'evento CurrentChanged .

Si applica a