示例#1
0
        /// <summary>
        /// The <see cref="PhotoCamera.PhotoCaptured"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="capturedPhoto">Captured photo.</param>
        private void CameraOnPhotoCaptured(object sender, ICapturedPhoto capturedPhoto)
        {
            // In our application we capture only single frame, so we can update view model state in
            // the current method.
            // If your application captures multiple frames, you may want to modify the 'CameraOnCaptureStopped'
            // method or add additional logic here.
            DispatcherHelper.BeginInvokeOnUIThread(async() =>
            {
                this.State = MainPageViewModelState.SavingCaptureResult;
                this.NotifyFocusStateChanged(new FocusStateChangedEventArgs(FocusState.Unlocked));

                try
                {
                    using (capturedPhoto)
                    {
                        IThumbnailedImage image = await this.storageService.SaveResultToCameraRollAsync(capturedPhoto);

                        // Get the preview image.
                        BitmapImage source = new BitmapImage();
                        source.SetSource(image.GetThumbnailImage());

                        this.Items.Add(image);
                        this.ReviewImageBrush = new ImageBrush {
                            ImageSource = source
                        };
                    }
                }
                finally
                {
                    this.State = MainPageViewModelState.Loaded;
                }
            });
        }
        private static void OnDataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ThumbnailedImageViewer mediaItemViewer = (ThumbnailedImageViewer)d;

            IThumbnailedImage newPhoto = e.NewValue as IThumbnailedImage;

            mediaItemViewer.ClearImageSources();

            if (e.NewValue != null)
            {
                mediaItemViewer.ShowPlaceholder();
                mediaItemViewer.BeginLoadingThumbnail();
            }
            else
            {
                mediaItemViewer._image.Source = null;
            }
        }