CurrentChangingEventHandler Délégué

Définition

Représente une méthode qui peut gérer l’événement CurrentChanging d’une implémentation ICollectionView .

/// [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)

Paramètres

sender
Object

IInspectable

Source de l'événement.

e
CurrentChangingEventArgs

Données d'événement.

Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

L’exemple de code suivant montre comment gérer l’événement CurrentChanging . Dans cet exemple, le code XAML montre le contenu d’une page avec un GridView lié à un Objet CollectionViewSource. Le code-behind affiche l’initialisation CollectionViewSource , qui inclut la définition de sa source et la récupération de son affichage afin d’attacher le gestionnaire d’événements 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;
    }
}

Remarques

L’événement ICollectionView.CurrentChanging se produit lorsque la valeur de la propriété CurrentItem change. Le paramètre CurrentChangingEventArgs passé au gestionnaire d’événements spécifie des informations sur la modification.

Si IsCancelable a la valeur true, le gestionnaire d’événements peut annuler la modification en définissant Annuler sur true. Si la modification est annulée, CurrentItem n’est pas modifié. Le fait de définir Annuler sur true lorsque IsCancelable a la valeur false génère une exception.

S’applique à

Voir aussi