private void ScanningAction(object obj) { IsScanning = false; ScanAgain = true; Device.BeginInvokeOnMainThread(async() => { await Task.Delay(100); try { IsBusy = true; var data = obj as Result; TextResult = data.Text; OnResultScanHandler?.Invoke(TextResult); await Application.Current.MainPage.Navigation.PopModalAsync(); Console.WriteLine(obj.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { IsBusy = false; } }); }
public BarcodeScannerViewModel() { ScanningCommand = new Command(ScanningAction, x => IsScanning); ScanAgainCommand = new Command(() => { IsScanning = true; ScanAgain = false; TextResult = string.Empty; }); TakeCommand = new Command(() => { Device.BeginInvokeOnMainThread(async() => { OnResultScanHandler?.Invoke(TextResult); await Task.Delay(1000); await Application.Current.MainPage.Navigation.PopModalAsync(); }); }); CancalCommand = new Command(() => { TextResult = string.Empty; Device.BeginInvokeOnMainThread(async() => { await Task.Delay(1000); await Application.Current.MainPage.Navigation.PopModalAsync(); }); }); Task.Run(() => StartScan()); }