Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example to show how to do navigation with tabbed pages #66

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions 08-TabbedNavigation/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Tabbed Navigation

TODO
[Tabbed Page Docs](https://prismlibrary.github.io/docs/xamarin-forms/navigation/working-with-tabbedpages.html)

- Show Creating a Tabbed Page with tabs via querystring
- Show Selecting the visible tab via querystring
- Show Changing Tabs
## This example shows the following

- Creating a tab page in xaml and navigating to a tab with the query string
- Create tabs at runtime with the query string
- Navigating to a tab via the query string
- Changing to another tab with the navigation service
8 changes: 8 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();

containerRegistry.RegisterForNavigation<TabsPage, TabsPageViewModel>();

containerRegistry.RegisterForNavigation<TabAPage, TabAPageViewModel>();
containerRegistry.RegisterForNavigation<TabBPage, TabBPageViewModel>();
containerRegistry.RegisterForNavigation<TabCPage, TabCPageViewModel>();

containerRegistry.RegisterForNavigation<DynamicTabsPage, DynamicTabsPageViewModel>();
ScarlettCode marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
18 changes: 18 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/PrismSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,22 @@
<PackageReference Include="Prism.DryIoc.Forms" Version="7.2.0.1422" />
<PackageReference Include="Xamarin.Forms" Version="4.3.0.991211" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Views\DynamicTabsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\TabAPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\TabBPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\TabCPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\TabsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
ScarlettCode marked this conversation as resolved.
Show resolved Hide resolved
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrismSample.ViewModels
{
public class DynamicTabsPageViewModel : BindableBase
{
public DynamicTabsPageViewModel()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using PrismSample.Views;

namespace PrismSample.ViewModels
{
public class MainPageViewModel : BindableBase
{
private readonly INavigationService _navigationService;
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
public DelegateCommand DynamicTabsCommand { get; set; }
public DelegateCommand TabBCommand { get; set; }
public DelegateCommand TabCCommand { get; set; }

public MainPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
TabBCommand = new DelegateCommand(TabBAction);
TabCCommand = new DelegateCommand(TabCAction);
DynamicTabsCommand = new DelegateCommand(DynamicTabsAction);
}

private async void DynamicTabsAction()
{
// Notice that with the DynamicTabsPage.xaml page we haven't specified any tabs.
ScarlettCode marked this conversation as resolved.
Show resolved Hide resolved
// They are created on the fly when we navigate there
await _navigationService.NavigateAsync(nameof(DynamicTabsPage) +
$"?{KnownNavigationParameters.CreateTab}=" + nameof(TabCPage) +
$"&{KnownNavigationParameters.CreateTab}=" + nameof(TabBPage) +
$"&{KnownNavigationParameters.CreateTab}=" + nameof(TabAPage));
}

private async void TabBAction()
{
await _navigationService.NavigateAsync(nameof(TabsPage) + $"?{KnownNavigationParameters.SelectedTab}=" + nameof(TabBPage));
}

private async void TabCAction()
{
await _navigationService.NavigateAsync(nameof(TabsPage) + "?selectedTab=" + nameof(TabCPage));
}
ScarlettCode marked this conversation as resolved.
Show resolved Hide resolved

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrismSample.ViewModels
{
public class TabAPageViewModel : BindableBase
{
public TabAPageViewModel()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrismSample.ViewModels
{
public class TabBPageViewModel : BindableBase
{
public TabBPageViewModel()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Navigation.TabbedPages;
using PrismSample.Views;

namespace PrismSample.ViewModels
{
public class TabCPageViewModel : BindableBase
{
private readonly INavigationService _navigationService;
public DelegateCommand TabACommand { get; set; }
dansiegel marked this conversation as resolved.
Show resolved Hide resolved

public TabCPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
TabACommand = new DelegateCommand(TabAAction);
}

private void TabAAction()
{
_navigationService.SelectTabAsync(nameof(TabAPage));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrismSample.ViewModels
{
public class TabsPageViewModel : BindableBase
{
public TabsPageViewModel()
{

}
Comment on lines +11 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a Title property... and be sure to wrap this page in a NavigationPage

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismSample.Views.DynamicTabsPage">

</TabbedPage>
12 changes: 12 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/DynamicTabsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace PrismSample.Views
{
public partial class DynamicTabsPage : TabbedPage
{
public DynamicTabsPage()
{
InitializeComponent();
}
}
}
12 changes: 7 additions & 5 deletions 08-TabbedNavigation/src/PrismSample/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
Title="Main Page"
x:Class="PrismSample.Views.MainPage">

<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
<StackLayout VerticalOptions="CenterAndExpand">

<Button Text="Create Tabs At Runtime" Command="{Binding DynamicTabsCommand}"></Button>
<Button Text="Go To Tab B" Command="{Binding TabBCommand}"></Button>
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
<Button Text="Go To Tab C" Command="{Binding TabCCommand}"></Button>

</StackLayout>

</ContentPage>
13 changes: 13 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabAPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismSample.Views.TabAPage"
Title="Tab A">

<StackLayout>
<Label Text="Tab A" HorizontalOptions="CenterAndExpand"></Label>
</StackLayout>

</ContentPage>
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabAPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace PrismSample.Views
{
public partial class TabAPage : ContentPage
{
public TabAPage()
{
InitializeComponent();
}
}
}
13 changes: 13 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabBPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismSample.Views.TabBPage"
Title="Tab B">

<StackLayout>
<Label Text="Tab B" HorizontalOptions="CenterAndExpand"></Label>
</StackLayout>

</ContentPage>
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabBPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace PrismSample.Views
{
public partial class TabBPage : ContentPage
{
public TabBPage()
{
InitializeComponent();
}
}
}
14 changes: 14 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabCPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the ViewModelLocator.AutowireViewModel property as it is not needed here.

x:Class="PrismSample.Views.TabCPage"
Title="Tab C">

<StackLayout>
<Label Text="Tab C" HorizontalOptions="CenterAndExpand"></Label>
<Button Text="Go To Tab A" HorizontalOptions="CenterAndExpand" Command="{Binding TabACommand}"></Button>
</StackLayout>
dansiegel marked this conversation as resolved.
Show resolved Hide resolved

</ContentPage>
12 changes: 12 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabCPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace PrismSample.Views
{
public partial class TabCPage : ContentPage
{
public TabCPage()
{
InitializeComponent();
}
}
}
15 changes: 15 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabsPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
xmlns:views="clr-namespace:PrismSample.Views;assembly=PrismSample"
prism:ViewModelLocator.AutowireViewModel="True"
dansiegel marked this conversation as resolved.
Show resolved Hide resolved
x:Class="PrismSample.Views.TabsPage">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to bind a the Title to the ViewModel


<TabbedPage.Children>
<views:TabAPage Title="Tab A" />
<views:TabBPage Title="Tab B"/>
<views:TabCPage Title="Tab C"/>
</TabbedPage.Children>

</TabbedPage>
12 changes: 12 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/Views/TabsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xamarin.Forms;

namespace PrismSample.Views
{
public partial class TabsPage : TabbedPage
{
public TabsPage()
{
InitializeComponent();
}
}
}