I have 2 buttons on a xamarin form,
scannerButton and checkOrderButton
scannerButton opens the scanner page, scans a QRCode and populates it into a order entry field
checkOrderButton reads whatever is in the order entry field and processes validations and sends it to server for verification
what I want - is to call the checkOrderButton.Click from within the scannerButton.Click - after it has scanned the text
code:
private async void scanCameraButton_Clicked(object sender, EventArgs e)
{
var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
ZXing.BarcodeFormat.QR_CODE,ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
};
var scanPage = new ZXingScannerPage(options);
scanPage.OnScanResult += (result) =>
{
//stop scan
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(() =>
{
//pop the page and get the result
Navigation.PopAsync();
orderNoEntry.Text = result.Text;
});
//invoke checkOrderButton.Click here
};
what would be the best approach to do this?
one alternate is to dump all the functionality from checkOrderButton.Click handler into a function and then call that function from both button clicks, but I'm interested in learning how I can invoke the click event programmatically
PerformClick
on the button? Though it would be a lot better design not to click buttons programmatically and rather just call methods.