CurrentChangingEventHandler Delegasikan
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili metode yang dapat menangani peristiwa CurrentChanging dari implementasi 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)
Parameter
- sender
-
Object
IInspectable
Sumber dari peristiwa tersebut.
Data peristiwa.
- Atribut
Persyaratan Windows
Rangkaian perangkat |
Windows 10 (diperkenalkan dalam 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)
|
Contoh
Contoh kode berikut menunjukkan cara menangani peristiwa CurrentChanging . Dalam contoh ini, XAML menampilkan konten halaman dengan GridView yang terikat ke CollectionViewSource. Kode di belakang menunjukkan inisialisasi CollectionViewSource , yang mencakup pengaturan Sumbernya dan mengambil Tampilannya untuk melampirkan penanganan aktivitas 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;
}
}
Keterangan
Peristiwa ICollectionView.CurrentChanging terjadi saat nilai properti CurrentItem berubah. Parameter CurrentChangingEventArgs yang diteruskan ke penanganan aktivitas menentukan informasi tentang perubahan.
Jika IsCancelablebenar, penanganan aktivitas dapat membatalkan perubahan dengan mengatur Batal ke true. Jika perubahan dibatalkan, CurrentItem tidak diubah. Pengaturan Batal ke true ketika IsCancelablefalse menimbulkan pengecualian.
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk