Esempio n. 1
0
        /// <summary>
        /// The <see cref="MainPageViewModel.PropertyChanged"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="PropertyChangingEventArgs"/> instance containing the event data.</param>
        private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            DispatcherHelper.InvokeOnUIThread(() =>
            {
                switch (e.PropertyName)
                {
                case MainPageViewModel.StatePropertyName:
                    this.SetChromeVisibility(this.viewModel.State == MainPageViewModelState.Loaded);
                    this.UpdateApplicationBarState();
                    break;

                case MainPageViewModel.ItemsPropertyName:
                    if (this.viewModel.Items != null)
                    {
                        this.viewModel.Items.CollectionChanged += this.ViewModelOnItemsCollectionChanged;
                    }

                    break;

                case MainPageViewModel.CameraTypePropertyName:
                    if (this.viewfinder != null)
                    {
                        this.viewfinder.CameraType = this.viewModel.CameraType;
                    }

                    this.UpdateApplicationBarState();
                    break;

                case MainPageViewModel.FlashModePropertyName:
                    if (this.viewfinder != null)
                    {
                        string message = string.Empty;
                        switch (this.viewModel.FlashMode)
                        {
                        case FlashMode.Off:
                            message = AppResources.FlashOffTextLabel;
                            break;

                        case FlashMode.On:
                            message = AppResources.FlashOnTextLabel;
                            break;

                        case FlashMode.Auto:
                            message = AppResources.FlashAutoTextLabel;
                            break;
                        }

                        this.viewfinder.ShowStatusMessage(message);
                    }

                    this.UpdateApplicationBarState();

                    break;

                case MainPageViewModel.CaptureModePropertyName:
                    if (this.viewfinder != null)
                    {
                        string message = string.Empty;
                        switch (this.viewModel.CaptureMode)
                        {
                        case CaptureMode.LowLag:
                            message = AppResources.LowLagTextLabel;
                            break;

                        case CaptureMode.Variable:
                            message = AppResources.VariableTextLabel;
                            break;
                        }

                        this.viewfinder.ShowStatusMessage(message);
                    }

                    this.UpdateApplicationBarState();

                    break;

                case MainPageViewModel.PreviewBrushPropertyName:
                    if (this.viewfinder != null)
                    {
                        this.viewfinder.PreviewBrush = this.viewModel.PreviewBrush;
                    }

                    break;

                case MainPageViewModel.PreviewSizePropertyName:
                    if (this.viewfinder != null)
                    {
                        double max = Math.Max(this.viewModel.PreviewSize.Width, this.viewModel.PreviewSize.Height);
                        double min = Math.Min(this.viewModel.PreviewSize.Width, this.viewModel.PreviewSize.Height);

                        if (OrientationHelper.IsPortrait(this.Orientation))
                        {
                            this.viewfinder.PreviewHeight = max;
                            this.viewfinder.PreviewWidth  = min;
                        }
                        else
                        {
                            this.viewfinder.PreviewHeight = min;
                            this.viewfinder.PreviewWidth  = max;
                        }
                    }

                    break;

                case MainPageViewModel.ReviewImageBrushPropertyName:
                    if (this.viewfinder != null)
                    {
                        // If your application captures video and needs to slide the last
                        // video frame, please, refer to the Viewfinder.GetPreviewSnapshot method.
                        this.viewfinder.ReviewImageBrush = this.viewModel.ReviewImageBrush;
                        this.viewfinder.SlideReviewImage();
                    }

                    break;
                }
            });
        }