Appクラスの書き換え
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
MainPage.xaml
SwipeGestureRecognizerを追加する(反応が悪いのでThreshold=”50″を設定)
<?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="ScrollView01.MainPage">
<ContentPage.Content>
<StackLayout x:Name="stackLayout">
<StackLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Threshold="50" Swiped="OnSwiped"/>
</StackLayout.GestureRecognizers>
<Label Text="MainPage"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
MainPage.xaml.csにOnSwiped()を追加する
ナビゲーション スタックに Page1 を追加する
private void OnSwiped(object sender, SwipedEventArgs e)
{
Navigation.PushAsync(new Page1(), true);
}
Page1.xamlの作成
<?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="ScrollView01.Page1">
<ContentPage.Content>
<StackLayout>
<StackLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Right" Threshold="50" Swiped="OnSwiped"/>
</StackLayout.GestureRecognizers>
<Label Text="Page1"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Page1.xaml.csにOnSwiped()を追加する
Navigation.PopAsync(true) でナビゲーション スタックから Page1 を削除する
private void OnSwiped(object sender, SwipedEventArgs e)
{
Navigation.PopAsync(true);
}