I implemented un CameraBarcodeReaderView
of ZXing.Net.Maui
for reader codes QR, for this i did:
I have two ContentPage's, one its my principal (MainPage) view and other second contentpage content the CameraBarcodeReaderView
component (SecondPage). The Second page it's called through of a button from MainPage.
// Called SecondPage from button of MainPage
{
await Navigation.PushModalAsync(new SecondPage(this));
}
When the CameraBarcodeReaderView
detected a valid Code QR, returning the value of code QR to MainPage and returning to MainPage the focus of app.
protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
if (detected==0)
{
detected = 1;
ReturnMainPage(e.Results[0].Value);
}
}
/// <summary>
/// Returning to MainPage the code detected from camara
/// </summary>
/// <param name="code">Code detected from camara</param>
public async void ReturnMainPage(string code)
{
pather_clients.code = code;
await App.Current.MainPage.Navigation.PopModalAsync();
WeakReferenceMessenger.Default.Send(MainPage);
}
But the problem is that the CameraBarcodeReaderView
component stays active and continuous reading QR Codes and I can't stop it.
How do I stop this CameraBarcodeReaderView
component?
or
How do I Remove/Delete/Disponse the SecondPage?
or
Does anyone have a better way to implement the CameraBarcodeReaderView
component?
Your post states that the
CameraBarcodeReaderView
"stays active" and performs "continuous reading". There are two booleans that you can use to idle it, and the one I would personally use isIsDetecting
, shown here with a binding to the view model (and there is alsoIsEnabled
).For a working example of this, including a GitHub code repo, see my answer to this question because it does the very thing you're asking about.