private void ImageList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ImageList.SelectedItem != null) { ListViewItem item = (ListViewItem)ImageList.ContainerFromItem(ImageList.SelectedItem); Uri imageSource = _imageUriGetterFunc(item.Content, true); if (_crossFadeBatch == null) { // Save the previous image for a cross-fade _previousSurfaceBrush.Surface = BackgroundImage.SurfaceBrush.Surface; _previousSurfaceBrush.CenterPoint = BackgroundImage.SurfaceBrush.CenterPoint; _previousSurfaceBrush.Stretch = BackgroundImage.SurfaceBrush.Stretch; // Load the new background image BackgroundImage.ImageOpened += BackgroundImage_ImageChanged; } // Update the images BackgroundImage.Source = imageSource; PrimaryImage.Source = imageSource; if (!_transition.Completed) { _transition.Cancel(); } // Kick off a connected animation to animate from it's current position to it's new location CompositionImage image = VisualTreeHelperExtensions.GetFirstDescendantOfType <CompositionImage>(item); _transition.Initialize(this, image, null); _transition.Start(this, PrimaryImage, null, null); } }
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(ViewModel.IsRunning)) { ShowStatusMessage(); } else if (e.PropertyName == nameof(ViewModel.IsStatusLoading)) { if (ViewModel.IsStatusLoading) { ShowInfo("Loading status..."); } else { ShowStatusMessage(); } } else if (e.PropertyName == nameof(ViewModel.IsDownloading)) { if (ViewModel.IsDownloading) { ShowInfo("Downloading image..."); } } else if (e.PropertyName == nameof(ViewModel.SelectedImage)) { if (ViewModel.SelectedImage != null) { FlipViewItem item = (FlipViewItem)ImageList.ContainerFromItem(ViewModel.SelectedImage); ScrollViewer itemView = (ScrollViewer)item.ContentTemplateRoot; zoom.Apply(itemView, ViewModel.SelectedImage); } } }
/// <summary> /// 使用动画效果更改当前显示的图片 /// </summary> /// <param name="e">需要显示的图片</param> private void ChangeDisplayImage(PhotoDisplaySupport e) { FileName.Text = e.FileName; DisplayFile = e.PhotoFile; DisplayImage.Opacity = 0; Image image = ((ImageList.ContainerFromItem(e) as ListViewItem).ContentTemplateRoot as FrameworkElement).FindName("Photo") as Image; ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("PhotoAnimation", image).Configuration = new BasicConnectedAnimationConfiguration(); ConnectedAnimationService.GetForCurrentView().DefaultDuration = TimeSpan.FromMilliseconds(600); FadeOut.Begin(); SelectedPhotoID = e.PhotoFile.FolderRelativeId; }
private void ImageList_ItemClick(object sender, ItemClickEventArgs e) { ListViewItem item = (ListViewItem)ImageList.ContainerFromItem(e.ClickedItem); // If we near the edges of the list, scroll more into view GeneralTransform coordinate = item.TransformToVisual(ImageList); Point position = coordinate.TransformPoint(new Point(0, 0)); if ((position.X + item.ActualWidth >= ImageList.ActualWidth) || (position.X - item.ActualWidth <= 0)) { double delta = position.X - item.ActualWidth <= 0 ? -item.ActualWidth : item.ActualWidth; delta *= 1.5; ScrollViewer scroller = ImageList.GetFirstDescendantOfType <ScrollViewer>(); scroller.ChangeView(scroller.HorizontalOffset + delta, null, null); } }