private void OnImageLoadingImageLoading(object sender, ImageLoadingEventArgs e) { if (string.IsNullOrEmpty(e.FileName)) { return; } var vm = ParentViewModel as ILoadImageHandler; if (vm == null) { return; } var fileinfo = new FileInfo(e.FileName); if (fileinfo.Exists) { e.IsCanceled = !vm.ValidateFileSize(fileinfo.Length); } }
/// <summary> /// Image is loading in image viewer. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ImageLoadingEventArgs"/> instance containing the event data.</param> private void ImageViewer_ImageLoading(object sender, ImageLoadingEventArgs e) { // if scrolling is in progress if (_scrollAction != ScrollAction.None) { ImageViewer.ImageLoading -= new EventHandler <ImageLoadingEventArgs>(ImageViewer_ImageLoading); float autoScrollPositionX; float autoScrollPositionY; // autoScrollPositionX float proportion = (float)ImageViewer.Image.Width / _previouslyFocusedImageWidth; autoScrollPositionX = _previouslyFocusedImageAutoScrollPositionX * proportion; // autoScrollPositionY switch (_scrollAction) { case ScrollAction.MoveToNextPage: autoScrollPositionY = 0; break; case ScrollAction.MoveToPreviousPage: autoScrollPositionY = ImageViewer.Image.Height; break; default: throw new Exception(); } // set scroll of new focused image ImageViewer.ViewerState.AutoScrollPosition = new PointF(autoScrollPositionX, autoScrollPositionY); _scrollAction = ScrollAction.None; } _isPageChanging = false; }