diff options
author | Brian Lagunas <brian.lagunas@live.com> | 2016-06-01 05:12:48 +0300 |
---|---|---|
committer | Brian Lagunas <brian.lagunas@live.com> | 2016-06-01 05:12:48 +0300 |
commit | 2101d8042351bba07fe9a15195350279519607da (patch) | |
tree | 153cc1b78a11d769fea53b111b08aaf0782dd899 /Sandbox | |
parent | 9cf01c7dfd33f55a69f6d7d59f9d974eaf71b38e (diff) |
fixed async/await behavior
Diffstat (limited to 'Sandbox')
3 files changed, 27 insertions, 9 deletions
diff --git a/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs b/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs index 81eb1bf..b6b187d 100644 --- a/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs +++ b/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs @@ -10,7 +10,7 @@ namespace HelloWorld { protected override void OnInitialized() { - NavigationService.NavigateAsync("MyMasterDetail/MyNavigationPage/MainPage", animated: false); + NavigationService.NavigateAsync("ViewA", animated: false); } protected override void RegisterTypes() diff --git a/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewAViewModel.cs b/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewAViewModel.cs index 46e3a6c..3fde922 100644 --- a/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewAViewModel.cs +++ b/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewAViewModel.cs @@ -1,4 +1,5 @@ -using Prism.Commands; +using System; +using Prism.Commands; using Prism.Mvvm; using Prism.Navigation; @@ -15,18 +16,27 @@ namespace ModuleA.ViewModels set { SetProperty(ref _title, value); } } + private bool _canNavigate = true; + public bool CanNavigate + { + get { return _canNavigate; } + set { SetProperty(ref _canNavigate, value); } + } + public DelegateCommand NavigateCommand { get; set; } public ViewAViewModel(INavigationService navigationService) { _navigationService = navigationService; - NavigateCommand = new DelegateCommand(Navigate); + NavigateCommand = new DelegateCommand(Navigate).ObservesCanExecute((vm) => CanNavigate); } - void Navigate() + async void Navigate() { - _navigationService.NavigateAsync("ViewB"); + CanNavigate = false; + await _navigationService.NavigateAsync("ViewB"); + CanNavigate = true; } public void OnNavigatedFrom(NavigationParameters parameters) diff --git a/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewBViewModel.cs b/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewBViewModel.cs index ac31c8d..2f697ca 100644 --- a/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewBViewModel.cs +++ b/Sandbox/Xamarin/HelloWorld/ModuleA/ViewModels/ViewBViewModel.cs @@ -16,18 +16,26 @@ namespace ModuleA.ViewModels set { SetProperty(ref _title, value); } } + private bool _canNavigate = true; + public bool CanNavigate + { + get { return _canNavigate; } + set { SetProperty(ref _canNavigate, value); } + } + public DelegateCommand NavigateCommand { get; set; } public ViewBViewModel(INavigationService navigationService) { _navigationService = navigationService; - - NavigateCommand = new DelegateCommand(Navigate); + NavigateCommand = new DelegateCommand(Navigate).ObservesCanExecute((vm) => CanNavigate); } - void Navigate() + async void Navigate() { - _navigationService.GoBackAsync(); + CanNavigate = false; + await _navigationService.GoBackAsync(); + CanNavigate = true; } public void OnNavigatedFrom(NavigationParameters parameters) |