我新的xamarin,我试图使一个按钮,打开一个扫描仪的形式,扫描qr/条形码,这是MVVM的方法。我试图得到的结果,并显示成一个标签。这是我最好的客人,但它不工作,希望有人能帮助。
view:
<StackLayout>
<Label Text="{Binding CodigoQr}"/>
<zxing:ZXingScannerView x:Name="ucZXingScannerView"
IsScanning="True"
IsAnalyzing="True"
Result="{Binding CodigoQr}"
ScanResultCommand="{Binding ScanCommand }" />
</StackLayout>
ViewModel:
public class BarcodeScanVM : BaseViewModel
{
private Result _codigoQr;
public Result CodigoQr
{
get { return _codigoQr; }
set
{
_codigoQr = value;
OnPropertyChanged();
}
}
public AsyncCommand ScanCommand { get; set; }
public BarcodeScanVM()
{
ScanCommand = new AsyncCommand(OnScanResultCommand);
}
async Task OnScanResultCommand()
{
var text = CodigoQr;
}
}```
4条答案
按热度按时间iecba09b1#
You can use the code-behind the view for the actions. And use the VM for other properties
XAML:
Code behind:
62lalag42#
尝试不使用ScannerView。在XAML中添加一个标签(我使用的是条目)和一个打开扫描仪的按钮:
在按钮的Clicked事件上:
nmpmafwu3#
更新:我试过这个,看起来扫描命令起作用了,但是程序后来停止了。
xvw2m8pv4#
您可以在github上给予我的示例应用程序
xam-barcode-scanner
它可以在两个平台上工作,并且不需要ZXing库