CurrentChangingEventArgs Classe

Definizione

Fornisce i dati per l'evento 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
Ereditarietà
Object IInspectable CurrentChangingEventArgs
Attributi

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 controllo GridView associato a CollectionViewSource. Il code-behind mostra l'inizializzazione CollectionViewSource , che include l'impostazione dell'origine e il recupero della relativa 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 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