酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

Xamarin.Formsでタブ表示させるためにTabbedPageを使う

メモです。この記事で作成したプロジェクトを流用しています。

タブ表示させる

MyTabbedPage.xamlを追加します。

MyTabbedPage.xaml

<?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:local="clr-namespace:RealmSample"  
    x:Class="RealmSample.MyTabbedPage">

    <NavigationPage Title="tab1">
        <x:Arguments>
            <local:RealmSamplePage Title="page title"/>
        </x:Arguments>
    </NavigationPage>

</TabbedPage>

MyTabbedPage.xaml.cs

using Xamarin.Forms;

namespace RealmSample
{
    public partial class MyTabbedPage : TabbedPage
    {
        public MyTabbedPage()
        {
            InitializeComponent();
        }
    }
}

App.xaml.cs

using Xamarin.Forms;

namespace RealmSample
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new MyTabbedPage();
        }

        //...
    }
}

実行結果

実行しました。

f:id:ch3cooh393:20170109000914p:plain