シンプルなTabbedPageです。
ファイル --> 新規作成 --> プロジェクト(P)... --> Cross-Platform --> Xamarin-Forms で作成
TabbedPage02
TabPage.cs FirstPage.cs SecondPage.cs ThirdPage.cs クラスの追加
TabPage.csの書き換え
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabbedPage02
{
public class TabPage : TabbedPage
{
public TabPage()
{
this.Title = "Tabs Using
TabbedPage";
this.Children.Add(new FirstPage());
this.Children.Add(new
SecondPage());
this.Children.Add(new ThirdPage());
}
}
}
FirstPage.cs サブクラスの記述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabbedPage02
{
public class FirstPage : ContentPage
{
Button firstButton;
public FirstPage()
{
Title = "First Page";
Label homeLabel = new Label
{
Text = "First Page",
FontSize = 40
};
firstButton = new Button
{
Text = "Go to Second
Page"
};
firstButton.Clicked += async (sendernav, args)
=>
await Navigation.PushModalAsync(new
SecondPage());
var stackLayout = new StackLayout
{
Children = { homeLabel, firstButton
}
};
this.Content = stackLayout;
Application.Current.Properties["id"] =
12345;
}
}
}
SecondPage.cs の追加
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabbedPage02
{
public class SecondPage : ContentPage
{
Button secondButton;
public SecondPage()
{
Title = "Second Page";
Label homeLabel = new Label
{
Text = "Second Page",
FontSize = 40
};
secondButton = new Button
{
Text = "Go to Third
Page"
};
secondButton.Clicked += async (sendernav, args)
=>
await Navigation.PushModalAsync(new
ThirdPage());
var stackLayout = new StackLayout
{
Children = { homeLabel, secondButton
}
};
this.Content = stackLayout;
}
}
}
ThirdPage.cs の追加
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabbedPage02
{
public class ThirdPage : ContentPage
{
public ThirdPage()
{
Title = "Third Page";
Label homeLabel = new Label
{
Text = "Third Page",
FontSize = 40
};
var stackLayout = new StackLayout
{
Children = { homeLabel
}
};
this.Content = stackLayout;
}
}
}
App.cs の書き換え
App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace TabbedPage02
{
public class App : Application
{
public App()
{
// The root page of your
application
MainPage = new TabPage();
}
}
}
コメントをお書きください