protected virtual void SetupBindings()
        {
            _isConnectedBinding = this.SetBinding(() => DeviceVm.IsConnected).WhenSourceChanges(() =>
                {
                    System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged IsConnected");

                    var navService = ServiceLocator.Current.GetInstance<INavigationService>();
                    if (!DeviceVm.IsConnected && navService.CurrentPageKey == _viewPageKey)
                    {
                        System.Diagnostics.Debug.WriteLine("Navigating back since device is not connected anymore.");
                        navService.GoBack();
                    }
                });
            _isConnectedBinding.ForceUpdateValueFromSourceToTarget();

            _programModeBinding = this.SetBinding(() => DeviceVm.ProgramMode).WhenSourceChanges(() =>
                {
                    System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged ProgramMode");

                    var navService = ServiceLocator.Current.GetInstance<INavigationService>();
                    if (_programMode != MoCoBusProgramMode.Invalid && DeviceVm.ProgramMode != _programMode && navService.CurrentPageKey == _viewPageKey)
                    {
                        System.Diagnostics.Debug.WriteLine("Navigating back since ProgramMode was changed to another mode");
                        navService.GoBack();
                    }
                });
            _programModeBinding.ForceUpdateValueFromSourceToTarget();
        }
예제 #2
0
        public override void OnResume()
        {
            base.OnResume();

            System.Diagnostics.Debug.WriteLine("ModeSmsViewFragment OnResume");

            _prevRunStatus = MoCoBusRunStatus.Stopped;
            _runStatusBinding = this.SetBinding(() => DeviceVm.RunStatus)
                .WhenSourceChanges(() =>
                    {
                        System.Diagnostics.Debug.WriteLine("ModeSmsViewFragment RunStatus Changed (new={0},prev={1})", DeviceVm.RunStatus, _prevRunStatus);

                        lock (_runStatusLock)
                        {
                            if (DeviceVm.RunStatus != MoCoBusRunStatus.Stopped && DeviceVm.RunStatus != _prevRunStatus && !DeviceVm.IsUpdateTaskRunning)
                            {
                                System.Diagnostics.Debug.WriteLine("ModeSmsViewFragment RunStatus Changed: Looking for dialog");

                                var dlg = FragmentManager.FindFragmentByTag<DialogFragment>(Consts.DialogTag);
                                if (dlg == null)
                                {
                                    System.Diagnostics.Debug.WriteLine("ModeSmsViewFragment RunStatus Changed: Create ModeSmsStatusViewFragment");

                                    var ft = FragmentManager.BeginTransaction();
                                    ft.DisallowAddToBackStack();
                                    var dlg2 = ModeSmsStatusViewFragment.NewInstance();
                                    dlg2.Stoped += (oo, ee) => { };
                                    dlg2.Paused += (oo, ee) => { };
                                    dlg2.Resumed += (oo, ee) => { };
                                    dlg2.SetCommand("Stoped", Vm.StopProgramCommand);
                                    dlg2.SetCommand("Paused", Vm.PauseProgramCommand);
                                    dlg2.SetCommand("Resumed", Vm.StartProgramCommand);
                                    dlg2.Show(ft, Consts.DialogTag);
                                }
                                DeviceVm.StartUpdateTask();
                            }
                        }

                        _prevRunStatus = DeviceVm.RunStatus;
                    });
            _runStatusBinding.ForceUpdateValueFromSourceToTarget();

            _exposureTimeBinding = this.SetBinding(() => Vm.ExposureTime)
                .WhenSourceChanges(() =>
                    {
                        ExposureTimeEditText.Text = $"{Vm.ExposureTime:F1}s";
                    });
            _exposureTimeBinding.ForceUpdateValueFromSourceToTarget();

            _preDelayTimeBinding = this.SetBinding(() => Vm.PreDelayTime)
                .WhenSourceChanges(() =>
                {
                    PreDelayTimeEditText.Text = $"{Vm.PreDelayTime:F1}s";
                });
            _preDelayTimeBinding.ForceUpdateValueFromSourceToTarget();

            _delayTimeBinding = this.SetBinding(() => Vm.DelayTime)
                .WhenSourceChanges(() =>
                    {
                        DelayTimeEditText.Text = $"{Vm.DelayTime:F1}s";
                    });
            _delayTimeBinding.ForceUpdateValueFromSourceToTarget();

            _intervalTimeBinding = this.SetBinding(() => Vm.IntervalTime)
                .WhenSourceChanges(() =>
                    {
                        IntervalTimeEditText.Text = $"{Vm.IntervalTime:F1}s";
                    });
            _intervalTimeBinding.ForceUpdateValueFromSourceToTarget();

            _durationTimeBinding = this.SetBinding(() => Vm.DurationTime)
                .WhenSourceChanges(() =>
                    {
                        DurationTimeEditText.Text = $"{(int)(Vm.DurationTime / 60)}:{(int)Vm.DurationTime % 60:00}m";
                    });
            _durationTimeBinding.ForceUpdateValueFromSourceToTarget();

            _maxShotsBinding = this.SetBinding(() => Vm.MaxShots)
                .WhenSourceChanges(() =>
                    {
                        MaxShotsEditText.Text = $"{Vm.MaxShots}";
                    });
            _maxShotsBinding.ForceUpdateValueFromSourceToTarget();

            _sliderStartPosBinding = this.SetBinding(() => Vm.SliderStartPosition)
                .WhenSourceChanges(() =>
                    {
                        SliderStartPosEditText.Text = $"{Vm.SliderStartPosition}";
                    });
            _sliderStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _sliderStopPosBinding = this.SetBinding(() => Vm.SliderStopPosition)
                .WhenSourceChanges(() =>
                    {
                        SliderStopPosEditText.Text = $"{Vm.SliderStopPosition}";
                    });
            _sliderStopPosBinding.ForceUpdateValueFromSourceToTarget();

            _panStartPosBinding = this.SetBinding(() => Vm.PanStartPosition)
                .WhenSourceChanges(() =>
                    {
                        PanStartPosEditText.Text = $"{(double)Vm.PanStartPosition / (190 * 200 * 16) * 360:F1}°";
                    });
            _panStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _panStopPosBinding = this.SetBinding(() => Vm.PanStopPosition)
                .WhenSourceChanges(() =>
                    {
                        PanStopPosEditText.Text = $"{(double)Vm.PanStopPosition / (190 * 200 * 16) * 360:F1}°";
                    });
            _panStopPosBinding.ForceUpdateValueFromSourceToTarget();

            _tiltStartPosBinding = this.SetBinding(() => Vm.TiltStartPosition)
                .WhenSourceChanges(() =>
                    {
                        TiltStartPosEditText.Text = $"{(double)Vm.TiltStartPosition / (190 * 200 * 16) * 360:F1}°";
                    });
            _tiltStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _tiltStopPosBinding = this.SetBinding(() => Vm.TiltStopPosition)
                .WhenSourceChanges(() =>
                    {
                        TiltStopPosEditText.Text = $"{(double)Vm.TiltStopPosition / (190 * 200 * 16) * 360:F1}°";
                    });
            _tiltStopPosBinding.ForceUpdateValueFromSourceToTarget();
        }
        protected override void SetupBindings()
        {
            DetachBindings();

            base.SetupBindings();

            _hemisphereBinding = this.SetBinding(() => Vm.Direction)
                .WhenSourceChanges(() =>
                    {
                        HemisphereValueLabel.Text = _hemispherePickerViewModel.Items[(int)Vm.Direction];
                        if ((AstroDirection)_hemispherePickerViewModel.SelectedIndex != Vm.Direction)
                        {
                            HemisphereValuePickerView.ReloadAllComponents();
                            HemisphereValuePickerView.Select((int)Vm.Direction, 0, !HemisphereValuePickerView.Hidden);
                        }
                    });
            _hemisphereBinding.ForceUpdateValueFromSourceToTarget();

            _speedBinding = this.SetBinding(() => Vm.Speed)
                .WhenSourceChanges(() =>
                    {
                        SpeedValueLabel.Text = _speedPickerViewModel.Items[(int)Vm.Speed];
                        if ((AstroSpeed)_speedPickerViewModel.SelectedIndex != Vm.Speed)
                        {
                            SpeedValuePickerView.ReloadAllComponents();
                            SpeedValuePickerView.Select((int)Vm.Speed, 0, !SpeedValuePickerView.Hidden);
                        }
                    });
            _speedBinding.ForceUpdateValueFromSourceToTarget();

            _runStatusBinding = this.SetBinding(() => DeviceVm.RunStatus).WhenSourceChanges(() =>
                {
                    var nav = ServiceLocator.Current.GetInstance<INavigationService>();
                    if (nav.CurrentPageKey != AppDelegate.ModeAstroViewKey) return;

                    if (DeviceVm.RunStatus != MoCoBusRunStatus.Stopped && nav.CurrentPageKey != AppDelegate.ModeAstroStatusViewKey && !_navigatedToStatusView && !DeviceVm.IsUpdateTaskRunning)
                    {
                        _navigatedToStatusView = true;
                        DeviceVm.StartUpdateTask();
                        nav.NavigateTo(AppDelegate.ModeAstroStatusViewKey, Vm);
                    }
                });
            _runStatusBinding.ForceUpdateValueFromSourceToTarget();
        }
        public override void OnResume()
        {
            base.OnResume();

            System.Diagnostics.Debug.WriteLine("ModeAstroViewFragment OnResume");

            _prevRunStatus = MoCoBusRunStatus.Stopped;
            _runStatusBinding = this.SetBinding(() => DeviceVm.RunStatus)
                .WhenSourceChanges(() =>
                    {
                        lock (_runStatusLock)
                        {
                            if (DeviceVm.RunStatus != MoCoBusRunStatus.Stopped && DeviceVm.RunStatus != _prevRunStatus && !DeviceVm.IsUpdateTaskRunning)
                            {
                                var dlg = FragmentManager.FindFragmentByTag<DialogFragment>(Consts.DialogTag);
                                if (dlg == null)
                                {
                                    var ft = FragmentManager.BeginTransaction();
                                    ft.DisallowAddToBackStack();
                                    var dlg2 = ModeAstroStatusViewFragment.NewInstance();
                                    dlg2.Stoped += (oo, ee) => { };
                                    dlg2.Paused += (oo, ee) => { };
                                    dlg2.Resumed += (oo, ee) => { };
                                    dlg2.SetCommand("Stoped", Vm.StopProgramCommand);
                                    dlg2.SetCommand("Paused", Vm.PauseProgramCommand);
                                    dlg2.SetCommand("Resumed", Vm.ResumeProgramCommand);
                                    dlg2.Show(ft, Consts.DialogTag);
                                }
                                DeviceVm.StartUpdateTask();
                            }
                        }

                        _prevRunStatus = DeviceVm.RunStatus;
                    });
            _runStatusBinding.ForceUpdateValueFromSourceToTarget();

            _sliderAxisRadioBinding = this.SetBinding(() => SliderAxisRadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (SliderAxisRadioButton.Checked)
                    {
                        Vm.Motors |= Motors.MotorSlider;
                    }
                    else
                    {
                        Vm.Motors &= ~Motors.MotorSlider;
                    }
                });

            _panAxisRadioBinding = this.SetBinding(() => PanAxisRadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (PanAxisRadioButton.Checked)
                    {
                        Vm.Motors |= Motors.MotorPan;
                    }
                    else
                    {
                        Vm.Motors &= ~Motors.MotorPan;
                    }
                });

            _tiltAxisRadioBinding = this.SetBinding(() => TiltAxisRadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (TiltAxisRadioButton.Checked)
                    {
                        Vm.Motors |= Motors.MotorTilt;
                    }
                    else
                    {
                        Vm.Motors &= ~Motors.MotorTilt;
                    }
                });

            _mdkV5RadioBinding = this.SetBinding(() => MdkV5RadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (MdkV5RadioButton.Checked)
                    {
                        Vm.GearType = GearType.MdkV5;
                    }
                });

            _mdkV6RadioBinding = this.SetBinding(() => MdkV6RadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (MdkV6RadioButton.Checked)
                    {
                        Vm.GearType = GearType.MdkV6;
                    }
                });

            _nicOTiltRadioBinding = this.SetBinding(() => NicOTiltRadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (NicOTiltRadioButton.Checked)
                    {
                        Vm.GearType = GearType.NicOTilt;
                    }
                });

            _otherMechanicsRadioBinding = this.SetBinding(() => OtherMechanicsRadioButton.Checked)
                .WhenSourceChanges(() =>
                {
                    if (OtherMechanicsRadioButton.Checked)
                    {
                        Vm.GearReduction = 60.0f;
                    }
                    OtherMechanicsGearReductionEditText.Enabled = OtherMechanicsRadioButton.Checked;
                });

            _northRadioBinding = this.SetBinding(() => NorthRadioButton.Checked)
                .WhenSourceChanges(() =>
                    {
                        if (NorthRadioButton.Checked) Vm.Direction = AstroDirection.North;
                    });
            _southRadioBinding = this.SetBinding(() => SouthRadioButton.Checked)
                .WhenSourceChanges(() =>
                    {
                        if (SouthRadioButton.Checked) Vm.Direction = AstroDirection.South;
                    });

            _siderealRadioBinding = this.SetBinding(() => SiderealRadioButton.Checked)
                .WhenSourceChanges(() =>
                    {
                        if (SiderealRadioButton.Checked) Vm.Speed = AstroSpeed.Sidereal;
                    });
            _lunarRadioBinding = this.SetBinding(() => LunarRadioButton.Checked)
                .WhenSourceChanges(() =>
                    {
                        if (LunarRadioButton.Checked) Vm.Speed = AstroSpeed.Lunar;
                    });

            _otherMechanicsGearReductionBinding = this.SetBinding(() => Vm.GearReduction)
                .WhenSourceChanges(() =>
                {
                    OtherMechanicsGearReductionEditText.Text = $"{Vm.GearReduction:F1}";
                });
        }
        void SetupBindings()
        {
            _isConnectedBinding = this.SetBinding(() => Vm.IsConnected, () => ConnectButton.On, BindingMode.TwoWay).UpdateTargetTrigger("ValueChanged");
            _isConnectedBinding.ValueChanged += (sender, e) =>
            {
                System.Diagnostics.Debug.WriteLine("DeviceViewModel PropertyChanged IsConnected");
                OnConnectionOrProgramModeChanged();
            };
            _isConnectedBinding.ForceUpdateValueFromSourceToTarget();

            _programModeBinding = this.SetBinding(() => Vm.ProgramMode).WhenSourceChanges(() =>
            {
                System.Diagnostics.Debug.WriteLine("DeviceViewModel PropertyChanged ProgramMode");
                OnConnectionOrProgramModeChanged();
                var navService = ServiceLocator.Current.GetInstance<INavigationService>();
                switch (Vm.ProgramMode)
                {
                    case MoCoBusProgramMode.ShootMoveShoot:
                        if (navService.CurrentPageKey != AppDelegate.ModeSmsViewKey && navService.CurrentPageKey != AppDelegate.ModeSmsStatusViewKey)
                        {
                            if (_modeChangeRequested || Vm.RunStatus != MoCoBusRunStatus.Stopped)
                            {
                                System.Diagnostics.Debug.WriteLine("Navigating to ModeSmsView since a mode change was requested");
                                _modeChangeRequested = false;
                                navService.NavigateTo(AppDelegate.ModeSmsViewKey, Vm.ModeSmsViewModel);
                            }
                        }
                        break;
                    case MoCoBusProgramMode.Panorama:
                        if (navService.CurrentPageKey != AppDelegate.ModePanoViewKey && navService.CurrentPageKey != AppDelegate.ModePanoStatusViewKey)
                        {
                            if (_modeChangeRequested || Vm.RunStatus != MoCoBusRunStatus.Stopped)
                            {
                                System.Diagnostics.Debug.WriteLine("Navigating to ModePanoView since a mode change was requested");
                                _modeChangeRequested = false;
                                navService.NavigateTo(AppDelegate.ModePanoViewKey, Vm.ModePanoViewModel);
                            }
                        }
                        break;
                    case MoCoBusProgramMode.Astro:
                        if (navService.CurrentPageKey != AppDelegate.ModeAstroViewKey && navService.CurrentPageKey != AppDelegate.ModeAstroStatusViewKey)
                        {
                            if (_modeChangeRequested || Vm.RunStatus != MoCoBusRunStatus.Stopped)
                            {
                                System.Diagnostics.Debug.WriteLine("Navigating to ModeAstroView since a mode change was requested");
                                _modeChangeRequested = false;
                                navService.NavigateTo(AppDelegate.ModeAstroViewKey, Vm.ModeAstroViewModel);
                            }
                        }
                        break;
                }
            });
            _programModeBinding.ForceUpdateValueFromSourceToTarget();
        }
        protected override void SetupBindings()
        {
            DetachBindings();

            base.SetupBindings();

            _exposureTimeBinding = this.SetBinding(() => Vm.ExposureTime).WhenSourceChanges(() =>
            {
                ExposureValueLabel.Text = $"{Vm.ExposureTime:F1}s";
                if ((decimal)ExposureValuePickerTableViewCell.Model.SelectedTime.TotalSeconds != Vm.ExposureTime)
                {
                    ExposureValuePickerTableViewCell.Model.SelectedTime = TimeSpan.FromSeconds((double)Vm.ExposureTime);
                }
            });
            _exposureTimeBinding.ForceUpdateValueFromSourceToTarget();

            _preDelayTimeBinding = this.SetBinding(() => Vm.PreDelayTime).WhenSourceChanges(() =>
            {
                PreDelayValueLabel.Text = $"{Vm.PreDelayTime:F1}s";
                if ((decimal)PreDelayValuePickerTableViewCell.Model.SelectedTime.TotalSeconds != Vm.PreDelayTime)
                {
                    PreDelayValuePickerTableViewCell.Model.SelectedTime = TimeSpan.FromSeconds((double)Vm.PreDelayTime);
                }
            });
            _preDelayTimeBinding.ForceUpdateValueFromSourceToTarget();

            _delayTimeBinding = this.SetBinding(() => Vm.DelayTime).WhenSourceChanges(() =>
            {
                PostDelayValueLabel.Text = $"{Vm.DelayTime:F1}s";
                if ((decimal)PostDelayValuePickerTableViewCell.Model.SelectedTime.TotalSeconds != Vm.DelayTime)
                {
                    PostDelayValuePickerTableViewCell.Model.SelectedTime = TimeSpan.FromSeconds((double)Vm.DelayTime);
                }
            });
            _delayTimeBinding.ForceUpdateValueFromSourceToTarget();

            _intervalTimeBinding = this.SetBinding(() => Vm.IntervalTime).WhenSourceChanges(() =>
            {
                IntervalValueLabel.Text = $"{Vm.IntervalTime:F1}s";
                if ((decimal)IntervalValuePickerTableViewCell.Model.SelectedTime.TotalSeconds != Vm.IntervalTime)
                {
                    IntervalValuePickerTableViewCell.Model.SelectedTime = TimeSpan.FromSeconds((double)Vm.IntervalTime);
                }
            });
            _intervalTimeBinding.ForceUpdateValueFromSourceToTarget();

            _durationTimeBinding = this.SetBinding(() => Vm.DurationTime).WhenSourceChanges(() =>
            {
                DurationValueLabel.Text = $"{(int) (Vm.DurationTime/60)}:{(int) Vm.DurationTime%60:00}m";
                if ((decimal)DurationValuePickerTableViewCell.Model.SelectedTime.TotalSeconds != Vm.DurationTime)
                {
                    DurationValuePickerTableViewCell.Model.SelectedTime = TimeSpan.FromSeconds((double)Vm.DurationTime);
                }
            });
            _durationTimeBinding.ForceUpdateValueFromSourceToTarget();

            _maxShotsBinding = this.SetBinding(() => Vm.MaxShots).WhenSourceChanges(() =>
            {
                ShotsValueLabel.Text = $"{Vm.MaxShots}";
                if (ShotsValuePickerTableViewCell.Model.SelectedNumber != Vm.MaxShots)
                {
                    ShotsValuePickerTableViewCell.Model.SelectedNumber = Vm.MaxShots;
                }
            });
            _maxShotsBinding.ForceUpdateValueFromSourceToTarget();

            _sliderStartPosBinding = this.SetBinding(() => Vm.SliderStartPosition).WhenSourceChanges(() =>
            {
                SliderStartPosValueLabel.Text = $"{Vm.SliderStartPosition}";
            });
            _sliderStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _sliderStopPosBinding = this.SetBinding(() => Vm.SliderStopPosition).WhenSourceChanges(() =>
            {
                SliderStopPosValueLabel.Text = $"{Vm.SliderStopPosition}";
            });
            _sliderStopPosBinding.ForceUpdateValueFromSourceToTarget();

            _panStartPosBinding = this.SetBinding(() => Vm.PanStartPosition).WhenSourceChanges(() =>
            {
                PanStartPosValueLabel.Text = $"{(double) Vm.PanStartPosition/(190*200*16)*360:F1}°";
            });
            _panStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _panStopPosBinding = this.SetBinding(() => Vm.PanStopPosition).WhenSourceChanges(() =>
            {
                PanStopPosValueLabel.Text = $"{(double) Vm.PanStopPosition/(190*200*16)*360:F1}°";
            });
            _panStopPosBinding.ForceUpdateValueFromSourceToTarget();

            _tiltStartPosBinding = this.SetBinding(() => Vm.TiltStartPosition).WhenSourceChanges(() =>
            {
                TiltStartPosValueLabel.Text = $"{(double) Vm.TiltStartPosition/(190*200*16)*360:F1}°";
            });
            _tiltStartPosBinding.ForceUpdateValueFromSourceToTarget();

            _tiltStopPosBinding = this.SetBinding(() => Vm.TiltStopPosition).WhenSourceChanges(() =>
            {
                TiltStopPosValueLabel.Text = $"{(double) Vm.TiltStopPosition/(190*200*16)*360:F1}°";
            });
            _tiltStopPosBinding.ForceUpdateValueFromSourceToTarget();

            _runStatusBinding = this.SetBinding(() => DeviceVm.RunStatus).WhenSourceChanges(() =>
            {
                var nav = ServiceLocator.Current.GetInstance<INavigationService>();

                System.Diagnostics.Debug.WriteLine($"ModeSmsViewController RunStatusBinding: CurrentPageKey={nav.CurrentPageKey}, RunStatus={DeviceVm.RunStatus}, _navigatedToStatusView={_navigatedToStatusView}");

                if (nav.CurrentPageKey != AppDelegate.ModeSmsViewKey)
                    return;
                if (DeviceVm.RunStatus != MoCoBusRunStatus.Stopped && nav.CurrentPageKey != AppDelegate.ModeSmsStatusViewKey && !_navigatedToStatusView && !DeviceVm.IsUpdateTaskRunning)
                {
                    System.Diagnostics.Debug.WriteLine($"ModeSmsViewController RunStatusBinding: Start update task and navigate to status view");
                    _navigatedToStatusView = true;
                    DeviceVm.StartUpdateTask();
                    nav.NavigateTo(AppDelegate.ModeSmsStatusViewKey, Vm);
                }
            });
            _runStatusBinding.ForceUpdateValueFromSourceToTarget();
        }
예제 #7
0
        protected override void OnResume()
        {
            base.OnResume();

            App.Initialize(this);
            ServiceLocator.Current.GetInstance<DispatcherHelper>().SetOwner(this);

            DisconnectedLayout.Visibility = ViewStates.Visible;
            ConnectingLayout.Visibility = ViewStates.Gone;
            ConnectedLayout.Visibility = ViewStates.Gone;

            _isConnectedBinding = this.SetBinding(() => Vm.IsConnected, () => ConnectSwitch.Checked, BindingMode.TwoWay);
            _showDisconnectedBinding = this.SetBinding(() => Vm.IsDisconnected, () => DisconnectedLayout.Visibility)
                .ConvertSourceToTarget(b => b ? ViewStates.Visible : ViewStates.Gone);
            _showConnectingBinding = this.SetBinding(() => Vm.IsConnecting, () => ConnectingLayout.Visibility)
                .ConvertSourceToTarget(b => b ? ViewStates.Visible : ViewStates.Gone);
            _showConnectedBinding = this.SetBinding(() => Vm.IsConnected)
                .WhenSourceChanges(() =>
                    {
                        System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed");

                        ConnectedLayout.Visibility = Vm.IsConnected ? ViewStates.Visible : ViewStates.Gone;

                        if (!Vm.IsConnected)
                        {
                            _programMode = MoCoBusProgramMode.Invalid;

                            System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: Search dialogs and close them");

                            var dlg = FragmentManager.FindFragmentByTag<DialogFragment>(Consts.DialogTag);
                            if (dlg != null)
                            {
                                System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: Found dialog, dismiss it");
                                dlg.DismissAllowingStateLoss();
                            }

                            System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: Search view fragment");
                            var f = FragmentManager.FindFragmentById<Fragment>(Resource.Id.ConnectedFragmentContainer);
                            if (f != null)
                            {
                                System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: Remove view fragment");
                                var ft = FragmentManager.BeginTransaction();
                                ft.Remove(f);
                                ft.SetTransition(FragmentTransit.FragmentFade);
                                ft.Commit();
                            }

                            System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: PopBackStackImmediate");
                            FragmentManager.PopBackStackImmediate(null, PopBackStackFlags.Inclusive);

                            System.Diagnostics.Debug.WriteLine("DeviceViewActivity IsConnected Changed: ExecutePendingTransactions");
                            FragmentManager.ExecutePendingTransactions();
                        }
                    });

            _programMode = MoCoBusProgramMode.Invalid;
            _programModeBinding = this.SetBinding(() => Vm.ProgramMode)
                .WhenSourceChanges(OnProgramModeChanged);
            _programModeBinding.ForceUpdateValueFromSourceToTarget();
        }