to make it easier to understand :
What i want to achive : PageA ->ScanningPage (done scanning) -> PageB
My current situation : ScanningPageViewModel : NavigateAsync("PageB ") ->Does Nothing.
Here's my code for the ScanningPage.(nothing fancy)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="MyApp.Views.PrismContentPage1">
<forms:ZXingScannerView IsScanning="{Binding IsScanning }" IsAnalyzing="{Binding IsAnalyzing}" Result="{Binding Result ,Mode=TwoWay}" ScanResultCommand="{Binding NavigateCommand }">
</forms:ZXingScannerView>
</ContentPage>
And in the viewmodel i just use the NavigationService to walk away from that page when i'm done scanning( or that's what i want to do) .
public class ScanningPageViewModel: BindableBase
{
private INavigationService _navigationService;
private bool _isAnalyzing = true;
private bool _isScanning = true;
public ZXing.Result Result { get; set; }
public bool IsAnalyzing
{
get { return _isAnalyzing; }
set
{
_isAnalyzing = value;
OnPropertyChanged();
}
}
public bool IsScanning
{
get { return _isScanning; }
set
{
_isScanning = value;
OnPropertyChanged();
}
}
public DelegateCommand NavigateCommand { get; private set; }
public ScanningPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateCommand = new DelegateCommand(Navigate, CanNavigate);
}
private void Navigate()
{
IsAnalyzing = false;
IsScanning = false;
_navigationService.NavigateAsync("Page3");
}
private bool CanNavigate()
{
return true;
}
}
When the scan it's complete the camera freezes and the app does nothing . In debug mode , in my ViewModel , on this line _navigationService.NavigateAsync("Page3") i get something like "Unknown member: NavigateAsync".
If I take out the ZXingScannerView from XAML and replace it with a button(or anything) and bind the button to the same command everything works fine .
Have i done something wrong? Is there a better way to do this?
Am currently running into same issue as yours. Were you able to get through this one ?
Thanks
Anu
I modified your sample like this and now its scanning and then returning to last page!
private void Navigate()
{
IsAnalyzing = false;
IsScanning = false;
GlobalVars.LastBarCode = Result.Text;
_navigationService.GoBackAsync();
}
Hey Guys, i had the same issue. Device.BeginInvokeOnMainThread did the trick for me.