forked from PrismLibrary/Prism-Samples-Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrismLibrary#77 from almirvuk/feature/ConfirmNavig…
…ation ConfirmNavigation Sample implementation.
- Loading branch information
Showing
14 changed files
with
198 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Confirm Navigation | ||
|
||
TODO | ||
* **ViewAPage** is tab page, and it contains `Switch` and `Button` control, `Switch` is binding to `CanNavigateAway` property. `ViewAPageViewModel ` is implementing `IConfirmNavigation` interface and `CanNavigateAway` is used for returning value in `CanNavigate` method. | ||
|
||
- Show use of IConfirmNavigation | ||
- Show use of IConfirmNavigationAsync | ||
* **ViewBPage** is tab page, and it contains `Button`, `Button` and `Command` property is binding to `NavigateAwayCommand`. `ViewBPageViewModel` is implementing `IConfirmNavigationAsync` interface and I am using `IPageDialogService` to ask user for confirm to navigate away, response from `DisplayAlertAsync` is used for return value of `CanNavigateAsync` method. | ||
|
||
* **ViewCPage** is only used for navigating to it, and to show some kind of message with `Label` control. It also has `Button` to navigate back (GoBacAsync). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
20-ConfirmNavigation/src/PrismSample/ViewModels/AsyncExamplePageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Threading.Tasks; | ||
using Prism.Navigation; | ||
using Prism.Commands; | ||
using Prism.Services; | ||
|
||
namespace PrismSample.ViewModels | ||
{ | ||
public class AsyncExamplePageViewModel : IConfirmNavigationAsync | ||
{ | ||
private readonly INavigationService _navigationService; | ||
private readonly IPageDialogService _pageDialogService; | ||
|
||
public DelegateCommand NavigateAwayCommand { get; private set; } | ||
|
||
public AsyncExamplePageViewModel(INavigationService navigationService, | ||
IPageDialogService pageDialogService) | ||
{ | ||
_navigationService = navigationService; | ||
_pageDialogService = pageDialogService; | ||
|
||
NavigateAwayCommand = new DelegateCommand(NavigateAway); | ||
} | ||
|
||
private async void NavigateAway() | ||
{ | ||
await _navigationService.NavigateAsync("ResultPage"); | ||
} | ||
|
||
public Task<bool> CanNavigateAsync(INavigationParameters parameters) | ||
{ | ||
return _pageDialogService.DisplayAlertAsync(string.Empty, "Are you sure you want to navigate away?", "Yes", "No"); | ||
} | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
20-ConfirmNavigation/src/PrismSample/ViewModels/MainPageViewModel.cs
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
20-ConfirmNavigation/src/PrismSample/ViewModels/NonAsyncExamplePageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Prism.Navigation; | ||
using Prism.Commands; | ||
using Prism.Mvvm; | ||
|
||
namespace PrismSample.ViewModels | ||
{ | ||
public class NonAsyncExamplePageViewModel : BindableBase, IConfirmNavigation | ||
{ | ||
private readonly INavigationService _navigationService; | ||
|
||
private bool _canNavigateAway; | ||
public bool CanNavigateAway | ||
{ | ||
get { return _canNavigateAway; } | ||
set { SetProperty(ref _canNavigateAway, value); } | ||
} | ||
|
||
public DelegateCommand NavigateAwayCommand { get; private set; } | ||
|
||
public NonAsyncExamplePageViewModel(INavigationService navigationService) | ||
{ | ||
_navigationService = navigationService; | ||
|
||
NavigateAwayCommand = new DelegateCommand(NavigateAway); | ||
} | ||
|
||
private async void NavigateAway() | ||
{ | ||
await _navigationService.NavigateAsync("ResultPage"); | ||
} | ||
|
||
public bool CanNavigate(INavigationParameters parameters) | ||
{ | ||
return CanNavigateAway; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
20-ConfirmNavigation/src/PrismSample/ViewModels/ResultPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Prism.Navigation; | ||
using Prism.Commands; | ||
|
||
namespace PrismSample.ViewModels | ||
{ | ||
public class ResultPageViewModel | ||
{ | ||
private readonly INavigationService _navigationService; | ||
|
||
public DelegateCommand GoBackCommand { get; private set; } | ||
|
||
public ResultPageViewModel(INavigationService navigationService) | ||
{ | ||
_navigationService = navigationService; | ||
|
||
GoBackCommand = new DelegateCommand(GoBack); | ||
} | ||
|
||
private async void GoBack() | ||
{ | ||
await _navigationService.GoBackAsync(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
20-ConfirmNavigation/src/PrismSample/Views/AsyncExamplePage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="PrismSample.Views.AsyncExamplePage" | ||
Title="Async"> | ||
<StackLayout VerticalOptions="Center" Margin="16"> | ||
|
||
<Label Text="IConfirmNavigationAsync Example" | ||
HorizontalOptions="Center"/> | ||
|
||
<Button Text="Navigate away" | ||
Command="{Binding NavigateAwayCommand}" | ||
HorizontalOptions="Center"/> | ||
|
||
</StackLayout> | ||
|
||
</ContentPage> |
12 changes: 12 additions & 0 deletions
12
20-ConfirmNavigation/src/PrismSample/Views/AsyncExamplePage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace PrismSample.Views | ||
{ | ||
public partial class AsyncExamplePage : ContentPage | ||
{ | ||
public AsyncExamplePage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
20-ConfirmNavigation/src/PrismSample/Views/MainPage.xaml.cs
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
20-ConfirmNavigation/src/PrismSample/Views/NonAsyncExamplePage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="PrismSample.Views.NonAsyncExamplePage" | ||
Title="Non-Async"> | ||
|
||
<StackLayout VerticalOptions="Center" | ||
Margin="16"> | ||
|
||
<Label Text="Can navigate?" | ||
HorizontalOptions="Center"/> | ||
|
||
<Switch IsToggled="{Binding CanNavigateAway}" | ||
HorizontalOptions="Center"/> | ||
|
||
<Button Text="Navigate away" | ||
HorizontalOptions="Center" | ||
Command="{Binding NavigateAwayCommand}"/> | ||
|
||
</StackLayout> | ||
|
||
</ContentPage> |
12 changes: 12 additions & 0 deletions
12
20-ConfirmNavigation/src/PrismSample/Views/NonAsyncExamplePage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace PrismSample.Views | ||
{ | ||
public partial class NonAsyncExamplePage : ContentPage | ||
{ | ||
public NonAsyncExamplePage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
20-ConfirmNavigation/src/PrismSample/Views/ResultPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="PrismSample.Views.ResultPage"> | ||
|
||
<StackLayout VerticalOptions="Center" Margin="16"> | ||
|
||
<Label Text="Congratulations! You did it!" | ||
FontAttributes="Bold" | ||
HorizontalOptions="Center"/> | ||
|
||
<Button Text="Go back" | ||
HorizontalOptions="Center" | ||
Command="{Binding GoBackCommand}" /> | ||
|
||
</StackLayout> | ||
|
||
</ContentPage> |
12 changes: 12 additions & 0 deletions
12
20-ConfirmNavigation/src/PrismSample/Views/ResultPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace PrismSample.Views | ||
{ | ||
public partial class ResultPage : ContentPage | ||
{ | ||
public ResultPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |