protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
        {
            base.OnNavigatedTo(isInHistory, disposables);

            Observable.FromEventPattern <WriteableBitmap>(_qrReader, nameof(_qrReader.NewImageArrived))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(args =>
            {
                if (QrImage == null)
                {
                    QrImage = args.EventArgs;
                }
                else
                {
                    ShowQrCameraDialogView.QrImage?.InvalidateVisual();
                }
            })
            .DisposeWith(disposables);

            Observable.FromEventPattern <string>(_qrReader, nameof(_qrReader.CorrectAddressFound))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(args => Close(DialogResultKind.Normal, args.EventArgs))
            .DisposeWith(disposables);

            Observable.FromEventPattern <string>(_qrReader, nameof(_qrReader.InvalidAddressFound))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(args => Message = $"Invalid QR code.")
            .DisposeWith(disposables);

            Observable.FromEventPattern <Exception>(_qrReader, nameof(_qrReader.ErrorOccured))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(async args =>
            {
                Close();
                await ShowErrorAsync(
                    Title,
                    args.EventArgs.Message,
                    "Something went wrong");
            })
            .DisposeWith(disposables);

            disposables.Add(Disposable.Create(() =>
            {
                RxApp.MainThreadScheduler.Schedule(async() => await _qrReader.StopScanningAsync());
            }));

            RxApp.MainThreadScheduler.Schedule(async() => await _qrReader.StartScanningAsync());
        }
Пример #2
0
 protected override void OnNavigatedFrom(bool isInHistory)
 {
     base.OnNavigatedFrom(isInHistory);
     RxApp.MainThreadScheduler.Schedule(async() => await _qrReader.StopScanningAsync());
 }