🚧 shell routes sample

pull/5/head
Marc CHEVALDONNE 7 months ago
parent 238c40172b
commit cf6a7c681a

@ -4,7 +4,7 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ex_ShellRoutes" xmlns:local="clr-namespace:ex_ShellRoutes"
Shell.FlyoutBehavior="Disabled" Shell.FlyoutBehavior="Flyout"
Title="ex_ShellRoutes"> Title="ex_ShellRoutes">
<ShellContent <ShellContent

@ -5,6 +5,15 @@ public partial class AppShell : Shell
public AppShell() public AppShell()
{ {
InitializeComponent(); InitializeComponent();
Routing.RegisterRoute("//newpage1", typeof(NewPage1)); Routing.RegisterRoute("page1", typeof(Page1));
Routing.RegisterRoute("//page1", typeof(Page1));
Routing.RegisterRoute("page1/page1_1", typeof(Page1_1));
Routing.RegisterRoute("page1/page1_2", typeof(Page1_2));
Routing.RegisterRoute("page1/page1_2/page1_2_1", typeof(Page1_2_1));
Routing.RegisterRoute("page1/page1_2/page1_2_2", typeof(Page1_2_2));
Routing.RegisterRoute("page1/page1_2/page1_2_3", typeof(Page1_2_3));
Routing.RegisterRoute("page1/page1_3", typeof(Page1_3));
Routing.RegisterRoute("page2", typeof(Page2));
Routing.RegisterRoute("//page1/page1_2/page1_2_2", typeof(Page1_2_2));
} }
} }

@ -7,31 +7,34 @@
<VerticalStackLayout <VerticalStackLayout
Padding="30,0" Padding="30,0"
Spacing="25"> Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
<Label <Label
Text="Hello, World!" Text="MainPage"
Style="{StaticResource Headline}" Style="{StaticResource Headline}"/>
SemanticProperties.HeadingLevel="Level1" />
<Label <Button
Text="Welcome to &#10;.NET Multi-platform App UI" Text="GoTo page1"
Style="{StaticResource SubHeadline}" Clicked="GoToPage1"
SemanticProperties.HeadingLevel="Level2" HorizontalOptions="Fill" />
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
<Button
Text="GoToAbsolute //page1"
Clicked="GoToAbsolutePage1"
HorizontalOptions="Fill" />
<Button
Text="GoTo page2"
Clicked="GoToPage2"
HorizontalOptions="Fill" />
<Button <Button
Text="GoToNewPage1" Text="GoTo page1/page1_2/page1_2_2"
Clicked="GoToNewPage1" Clicked="GoToPage1_2_2"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button <Button
Text="PushNewPage2" Text="GoToAbsolute //page1/page1_2/page1_2_2"
Clicked="PushNewPage2" Clicked="GoToAbsolutePage1_2_2"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>

@ -7,14 +7,29 @@ public partial class MainPage : ContentPage
InitializeComponent(); InitializeComponent();
} }
private async void GoToNewPage1(object sender, EventArgs e) private async void GoToPage1(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//newpage1"); await Shell.Current.GoToAsync("page1");
} }
private async void PushNewPage2(object sender, EventArgs e) private async void GoToAbsolutePage1(object sender, EventArgs e)
{ {
await Navigation.PushAsync(new NewPage2()); await Shell.Current.GoToAsync("//page1");
}
private async void GoToPage2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page2");
}
private async void GoToPage1_2_2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1/page1_2/page1_2_2");
}
private async void GoToAbsolutePage1_2_2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//page1/page1_2/page1_2_2");
} }
} }

@ -13,11 +13,22 @@
Text="GoToNewPage1" Text="GoToNewPage1"
Clicked="GoToNewPage1" Clicked="GoToNewPage1"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button
Text="GoToAbsoluteNewPage1"
Clicked="GoToAbsoluteNewPage1"
HorizontalOptions="Fill" />
<Button <Button
Text="PushNewPage2" Text="PushNewPage2"
Clicked="PushNewPage2" Clicked="PushNewPage2"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button
Text="GoToNewPage4"
Clicked="GoToNewPage4"
HorizontalOptions="Fill" />
<Label Text="{Binding CurrentItem}"/> <Label Text="{Binding CurrentItem}"/>
<Label Text="{Binding CurrentPage}"/> <Label Text="{Binding CurrentPage}"/>
<Label Text="{Binding CurrentState}"/> <Label Text="{Binding CurrentState}"/>

@ -9,12 +9,23 @@ public partial class NewPage1 : ContentPage
} }
private async void GoToNewPage1(object sender, EventArgs e) private async void GoToNewPage1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage1");
}
private async void GoToAbsoluteNewPage1(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//newpage1"); await Shell.Current.GoToAsync("//newpage1");
} }
private async void PushNewPage2(object sender, EventArgs e) private async void PushNewPage2(object sender, EventArgs e)
{ {
//await Shell.Current.GoToAsync("newpage2");
await Navigation.PushAsync(new NewPage2()); await Navigation.PushAsync(new NewPage2());
} }
private async void GoToNewPage4(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage1/newpage4");
}
} }

@ -13,10 +13,21 @@
Clicked="GoToNewPage1" Clicked="GoToNewPage1"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button
Text="GoToAbsoluteNewPage1"
Clicked="GoToAbsoluteNewPage1"
HorizontalOptions="Fill" />
<Button <Button
Text="PushNewPage2" Text="PushNewPage2"
Clicked="PushNewPage2" Clicked="PushNewPage2"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button
Text="GoToNewPage3"
Clicked="GoToNewPage3"
HorizontalOptions="Fill" />
<Label Text="{Binding CurrentItem}"/> <Label Text="{Binding CurrentItem}"/>
<Label Text="{Binding CurrentPage}"/> <Label Text="{Binding CurrentPage}"/>
<Label Text="{Binding CurrentState}"/> <Label Text="{Binding CurrentState}"/>

@ -9,12 +9,23 @@ public partial class NewPage2 : ContentPage
} }
private async void GoToNewPage1(object sender, EventArgs e) private async void GoToNewPage1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage1");
}
private async void GoToAbsoluteNewPage1(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//newpage1"); await Shell.Current.GoToAsync("//newpage1");
} }
private async void PushNewPage2(object sender, EventArgs e) private async void PushNewPage2(object sender, EventArgs e)
{ {
//await Shell.Current.GoToAsync("newpage2");
await Navigation.PushAsync(new NewPage2()); await Navigation.PushAsync(new NewPage2());
} }
private async void GoToNewPage3(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage1/newpage3");
}
} }

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.NewPage3"
Title="NewPage3">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button
Text="GoTo /NewPage4"
Clicked="GoToNewPage4WithSlash"
HorizontalOptions="Fill" />
<Button
Text="GoTo NewPage4"
Clicked="GoToNewPage4WithoutSlash"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,19 @@
namespace ex_ShellRoutes;
public partial class NewPage3 : ContentPage
{
public NewPage3()
{
InitializeComponent();
}
private async void GoToNewPage4WithSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("/newpage4");
}
private async void GoToNewPage4WithoutSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage4");
}
}

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.NewPage4"
Title="NewPage4">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button
Text="GoTo /NewPage5"
Clicked="GoToNewPage5WithSlash"
HorizontalOptions="Fill" />
<Button
Text="GoTo NewPage5"
Clicked="GoToNewPage5WithoutSlash"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,19 @@
namespace ex_ShellRoutes;
public partial class NewPage4 : ContentPage
{
public NewPage4()
{
InitializeComponent();
}
private async void GoToNewPage5WithSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("/newpage5");
}
private async void GoToNewPage5WithoutSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage5");
}
}

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.NewPage5"
Title="NewPage5">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button
Text="GoTo /NewPage4"
Clicked="GoToNewPage4WithSlash"
HorizontalOptions="Fill" />
<Button
Text="GoTo NewPage4"
Clicked="GoToNewPage4WithoutSlash"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,19 @@
namespace ex_ShellRoutes;
public partial class NewPage5 : ContentPage
{
public NewPage5()
{
InitializeComponent();
}
private async void GoToNewPage4WithSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("/newpage4");
}
private async void GoToNewPage4WithoutSlash(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("newpage4");
}
}

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1"
Title="Page1">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
<Button
Text="GoTo page1_1"
Clicked="GoToPage1_1"
HorizontalOptions="Fill" />
<Button
Text="GoTo page1/page1_2"
Clicked="GoToPage1_2"
HorizontalOptions="Fill" />
<Button
Text="GoTo /page1_3"
Clicked="GoToPage1_3"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,31 @@
using System.Text;
namespace ex_ShellRoutes;
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
private async void GoToPage1_1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1_1");
}
private async void GoToPage1_2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1/page1_2");
}
private async void GoToPage1_3(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("/page1_3");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_1"
Title="Page1_1">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_1" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,16 @@
namespace ex_ShellRoutes;
public partial class Page1_1 : ContentPage
{
public Page1_1()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
}

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_2"
Title="Page1_2">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_2" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
<Button
Text="GoTo page1_2_1"
Clicked="GoToPage1_2_1"
HorizontalOptions="Fill" />
<Button
Text="GoTo page1_3"
Clicked="GoToPage1_3"
HorizontalOptions="Fill" />
<Button
Text="Go back then to page1_3"
Clicked="GoBackThenToPage1_3"
HorizontalOptions="Fill" />
<Button
Text="GoTo page1_2"
Clicked="GoToPage1_2"
HorizontalOptions="Fill" />
<Button
Text="GoTo page1/page1_1"
Clicked="GoToPage1_1"
HorizontalOptions="Fill" />
<Button
Text="GoTo //page1/page1_2/page1_2_2"
Clicked="GoToPage1_2_2"
HorizontalOptions="Fill" />
<Button
Text="GoTo page1/page1_2/page1_2_2"
Clicked="GoToPage1_2_2WithoutSlashes"
HorizontalOptions="Fill" />
<Button
Text="GoTo //page1"
Clicked="GoToPage1"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,56 @@
namespace ex_ShellRoutes;
public partial class Page1_2 : ContentPage
{
public Page1_2()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
private async void GoToPage1_2_1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1_2_1");
}
private async void GoToPage1_3(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1_3");
}
private async void GoBackThenToPage1_3(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("../page1_3");
}
private async void GoToPage1_2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1_2");
}
private async void GoToPage1_1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1/page1_1");
}
private async void GoToPage1_2_2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//page1/page1_2/page1_2_2");
}
private async void GoToPage1_2_2WithoutSlashes(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1/page1_2/page1_2_2");
}
private async void GoToPage1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//page1");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_2_1"
Title="Page1_2_1">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_2_1" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,14 @@
namespace ex_ShellRoutes;
public partial class Page1_2_1 : ContentPage
{
public Page1_2_1()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
}

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_2_2"
Title="Page1_2_2">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_2_2" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
<Button
Text="GoTo page1_2_1"
Clicked="GoToPage1_2_1"
HorizontalOptions="Fill" />
<Button
Text="Go back then To page1_2_3"
Clicked="GoBackThenToPage1_2_3"
HorizontalOptions="Fill" />
<Button
Text="Go Back"
Clicked="GoBack"
HorizontalOptions="Fill" />
<Button
Text="Go Back Twice then to page2"
Clicked="GoBackTwiceThenToPage2"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,34 @@
namespace ex_ShellRoutes;
public partial class Page1_2_2 : ContentPage
{
public Page1_2_2()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
private async void GoToPage1_2_1(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("page1_2_1");
}
private async void GoBackThenToPage1_2_3(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("../page1_2_3");
}
private async void GoBack(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("..");
}
private async void GoBackTwiceThenToPage2(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("../../page2");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_2_3"
Title="Page1_2_3">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_2_3" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,14 @@
namespace ex_ShellRoutes;
public partial class Page1_2_3 : ContentPage
{
public Page1_2_3()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page1_3"
Title="Page1_3">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page1_3" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,14 @@
namespace ex_ShellRoutes;
public partial class Page1_3 : ContentPage
{
public Page1_3()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ex_ShellRoutes.Page2"
Title="Page2">
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Label
Text="Page2" Style="{StaticResource Headline}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label x:Name="labelNavStack"/>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,14 @@
namespace ex_ShellRoutes;
public partial class Page2 : ContentPage
{
public Page2()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
labelNavStack.Text = Shell.Current.Navigation.NavigationStack.Aggregate("Stack", (total, next) => $"{total} > {next?.Title ?? ""}");
}
}
Loading…
Cancel
Save