private void ImagesView_LayoutUpdated(object sender, object e) { if (VSP == null) { VSP = ImagesView.ChildAt <VirtualizingStackPanel>(0, 0, 0, 0, 0, 0, 1); } if (VSP != null && TryResetZoom(ImagesView.SelectedItem)) { ImagesView.LayoutUpdated -= ImagesView_LayoutUpdated; } }
private void ImagesView_SelectionChanged(object sender, SelectionChangedEventArgs e) { VSP = ImagesView.ChildAt <VirtualizingStackPanel>(0, 0, 0, 0, 0, 0, 1); if (VSP == null) { // Items has not yet been visualized yet. We'll wait. ImagesView.LayoutUpdated += ImagesView_LayoutUpdated; } else if (e.AddedItems.Any()) { if (!TryResetZoom(e.AddedItems.First())) { // Cannot reset, item is not yet visualized ImagesView.LayoutUpdated += ImagesView_LayoutUpdated; } } }