Reputation: 7354
When a ZXingScannerPage
is shown with the following code/configuration this results in a view with an opaque background (see first screenshot below) and it is impossible to scan barcodes.
The default background color for the pages of the app is set in DefaultTheme.xaml
. Because ApplyToDerivedTypes
is set to True
this means the background color is also applied to
ZXingScannerPage
. However, setting Background="Transparent"
in BarcodeScannerPage.xaml
results in the calling view to be visible in the background.
This issue does not seem to happen when running the app in debug on the emulator or the device (see second screenshot below).
DefaultTheme.xaml
<Style TargetType="Page" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{StaticResource Primary}"/>
<Setter Property="Padding" Value="0"/>
</Style>
BarcodeScannerPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<zxing:ZXingScannerPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
x:Class="Views.BarcodeScannerPage"
IsScanning="True"
OnScanResult="OnScanResultEventHandler">
</zxing:ZXingScannerPage>
ScanBarcodeViewModel.cs
[RelayCommand]
public async Task ScanBarcodeClick()
{
var barcodeScannerPage = new BarcodeScannerPage();
barcodeScannerPage.OnScanSucceeded += BarcodeScannerPage_OnScanSucceeded;
await Navigation.PushModalAsync(barcodeScannerPage, true);
}
NavigationManager.cs
public class NavigationManager : INavigation
{
private INavigation _navigation;
public Task PushModalAsync(Page page, bool animated)
{
return MainThread.InvokeOnMainThreadAsync(async () => await _navigation.PushModalAsync(page, animated));
}
}
Upvotes: 0
Views: 122