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}";
                });
        }
        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();
        }
        public async Task UpdateState()
        {
            System.Diagnostics.Debug.WriteLine("UpdateState");

            try
            {
                _runStatus = await _protocolService.Main.GetRunStatus().ConfigureAwait(false);

                var tmpProgramMode = _programMode;
                _programMode = await _protocolService.Main.GetProgramMode().ConfigureAwait(false);
                if (tmpProgramMode != _programMode)
                {
                    switch (_programMode)
                    {
                        case MoCoBusProgramMode.ShootMoveShoot:
                            System.Diagnostics.Debug.WriteLine("UpdateState: Call ModeSmsViewModel.InitState()");
                            await ModeSmsViewModel.InitState().ConfigureAwait(false);
                            break;
                        case MoCoBusProgramMode.Panorama:
                            System.Diagnostics.Debug.WriteLine("UpdateState: Call ModePanoViewModel.InitState()");
                            await ModePanoViewModel.InitState().ConfigureAwait(false);
                            break;
                        case MoCoBusProgramMode.Astro:
                            System.Diagnostics.Debug.WriteLine("UpdateState: Call ModeAstroViewModel.InitState()");
                            await ModeAstroViewModel.InitState().ConfigureAwait(false);
                            break;
                    }
                }

                _dispatcherHelper.RunOnUIThread(() =>
                    {
                        System.Diagnostics.Debug.WriteLine("UpdateState: Call RaisePropertyChanged for ProgramMode");
                        RaisePropertyChanged(() => ProgramMode);
                        System.Diagnostics.Debug.WriteLine("UpdateState: Call RaisePropertyChanged for RunStatus");
                        RaisePropertyChanged(() => RunStatus);
                    });
            }
            catch (TimeoutException toe)
            {
                Insights.Report(toe);
            }
        }