Exemplo n.º 1
0
        public ShowQrCameraDialogViewModel(Network network)
        {
            _qrReader = new(network);

            SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);

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

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

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

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

            SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);
        }