Skip to content

Instantly share code, notes, and snippets.

@brunoportess
Last active September 5, 2017 23:12
Show Gist options
  • Save brunoportess/37195a85594b19a6d0332cfa5852d5de to your computer and use it in GitHub Desktop.
Save brunoportess/37195a85594b19a6d0332cfa5852d5de to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
xmlns:forms="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
x:Class="QrCodeSample.Views.VerificaQrCode">
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<forms:ZXingScannerView IsScanning="{Binding IsScanning}" IsAnalyzing="{Binding IsAnalyzing}" Result="{Binding Result, Mode=TwoWay}" ScanResultCommand="{Binding QRScanResultCommand}"></forms:ZXingScannerView>
<forms:ZXingDefaultOverlay TopText="QCLUB - Leitor QrCode" BottomText="Passe o leitor sobre o QrCode" ShowFlashButton="False" Opacity="0.9"></forms:ZXingDefaultOverlay>
</Grid>
</ContentPage>
public class VerificaQrCodeViewModel : BaseViewModel
{
public ZXing.Result Result { get; set; }
private INavigationService _navigationService;
private IPageDialogService _dialogService;
public DelegateCommand QRScanResultCommand { get; set; }
public VerificaQrCodeViewModel(INavigationService navigationService, IPageDialogService dialogService)
{
_navigationService = navigationService;
_dialogService = dialogService;
QRScanResultCommand = new DelegateCommand(ExecuteQRScanResultCommand);
}
private bool isAnalyzing = true;
public bool IsAnalyzing
{
get => isAnalyzing;
set => SetProperty(ref isAnalyzing, value);
}
private bool isScanning = true;
public bool IsScanning
{
get => isScanning;
set => SetProperty(ref isScanning, value);
}
public async void ExecuteQRScanResultCommand()
{
//tem que chamar pela mainThread pra trocar de tela fechando o leitor
Device.BeginInvokeOnMainThread(async () =>
{
//do your job here - Result.Text contains QR CODE
//await _dialogService.DisplayAlertAsync("Scanned Barcode", Result.Text, "OK");
});
}
}
@brunoportess
Copy link
Author

Usando o plugin ZXing com XAML e MVVM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment