CurrentChangingEventHandler Delegar

Definição

Representa um método que pode manipular o evento CurrentChanging de uma implementação 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)

Parâmetros

sender
Object

IInspectable

A fonte do evento.

e
CurrentChangingEventArgs

Os dados do evento.

Atributos

Requisitos do Windows

Família de dispositivos
Windows 10 (introduzida na 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduzida na v1.0)

Exemplos

O exemplo de código a seguir demonstra como manipular o evento CurrentChanging . Neste exemplo, o XAML mostra o conteúdo de uma página com um GridView associado a um CollectionViewSource. O code-behind mostra a inicialização collectionViewSource , que inclui a configuração de sua Origem e a recuperação de seu Modo de Exibição para anexar o manipulador de eventos 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;
    }
}

Comentários

O evento ICollectionView.CurrentChanging ocorre quando o valor da propriedade CurrentItem está sendo alterado. O parâmetro CurrentChangingEventArgs passado para o manipulador de eventos especifica informações sobre a alteração.

Se IsCancelable for true, o manipulador de eventos poderá cancelar a alteração definindo Cancelar como true. Se a alteração for cancelada, CurrentItem não será alterado. Definir Cancelar como true quando IsCancelable for false gera uma exceção.

Aplica-se a

Confira também