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 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace PrismSample.Droid
{
[Application(
Label = "Prism Sample",
Label = "Tabbed Navigation",
Icon = "@mipmap/icon"
)]
public class MainApplication : Application
Expand Down
7 changes: 7 additions & 0 deletions 08-TabbedNavigation/src/PrismSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ protected override async void OnInitialized()
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<TabbedPage>();

containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
containerRegistry.RegisterForNavigation<TabsPage, TabsPageViewModel>();

containerRegistry.RegisterForNavigation<TabAPage, TabAPageViewModel>();
containerRegistry.RegisterForNavigation<TabBPage, TabBPageViewModel>();
containerRegistry.RegisterForNavigation<TabCPage, TabCPageViewModel>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using PrismSample.Views;
using Xamarin.Forms;

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

public MainPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;

TabBCommand = new DelegateCommand(TabBAction);
RuntimeTabsCommand = new DelegateCommand(RuntimeTabsAction);
}

private async void RuntimeTabsAction()
{
await _navigationService.NavigateAsync("TabbedPage" +
$"?{KnownNavigationParameters.CreateTab}=TabCPage" +
$"&{KnownNavigationParameters.CreateTab}=TabBPage" +
$"&{KnownNavigationParameters.CreateTab}=TabAPage");
Comment on lines +27 to +29
Copy link
Member

Choose a reason for hiding this comment

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

// KnowNavigationParameters.CreateTab == createTab
createTab=TabCPage&createTab=TabBPage

}

private async void TabBAction()
{
await _navigationService.NavigateAsync("TabsPage?selectedTab=TabBPage");

}
}
}
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("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

}
}
11 changes: 6 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,11 @@
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 RuntimeTabsAction}"></Button>
<Button Text="Go To Tab B" Command="{Binding TabBCommand}"></Button>
dansiegel marked this conversation as resolved.
Show resolved Hide resolved

</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();
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Learn feature by feature how to use Prism in your apps!
| 5 | [Event Aggregator][5] | How to use the IEventAggregator to raise and listen to events. This shows how to use a simple event with a primitive type payload, generic event with payload &lt;T&gt;, and event with custom EventArgs. It also demonstrated how to subscribe to events published in Xamarin.Forms inside native code. |
| 6 | [Page Dialog Service][6] | How to use the IPageDialogService to display alerts and action sheets from within your ViewModels. |
| 7 | [Dialog Service][7] | coming soon |
| 8 | [Tabbed Navigation][8] | coming soon |
| 8 | [Tabbed Navigation][8] | How to do navigation with tabbed pages in Prism |
| 9 | [Master Detail][9] | coming soon |
| 10 | [Modules][10] | How to use Prism modularization to separate the application logic using IModule, IModuleManager, ModuleCatalog. |
| 11 | [Module Dependency][11] | coming soon |
Expand Down