【发布时间】:2021-04-05 12:51:26
【问题描述】:
<zxing:ZXingScannerView IsScanning="True" OnScanResult="OnScanResult"/>
我在 xaml 文件中有这个,但我想使用 mvvm,所以我在 viewmodel 中有 onscanresult 事件处理程序。我如何使用它而不是后面代码中的那个?
public void OnScanResult(ZXing.Result result)
{
Device.BeginInvokeOnMainThread(() =>
{
ScanResult = result.Text + " (type: " + result.BarcodeFormat + ")";
});
}
【问题讨论】:
-
使用 EventToCommand 行为,或者只是让事件处理程序调用您的 VM 方法。使用事件不一定会破坏 MVVM