TabbedPage Databoundです。
ファイル --> 新規作成 --> プロジェクト(P)... --> Cross-Platform --> Xamarin-Forms で作成
TabPageDatabound01
Main.cs TabItem.cs クラスの追加
NumberPage.cs クラスの追加
TabItem.csの書き換え
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabPageDatabound01
{
public class TabItem : ContentPage
{
public TabItem(string name, int number)
{
this.Name = name;
this.Number = number;
}
public string Name { private set; get; }
public int Number { private set; get; }
}
}
Main.csの書き換え
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace TabPageDatabound01
{
// Class TabbedPage
public class Main : TabbedPage
{
public Main()
{
this.Title = "Data-bound
TabbedPage";
this.ItemsSource = new TabItem[] {
new TabItem ("First",
1),
new TabItem ("Second",
2),
new TabItem ("Third",
3),
new TabItem ("Fourth",
4),
new TabItem ("Fifth",
5),
new TabItem ("Sixth",
6)
};
this.ItemTemplate = new DataTemplate(()
=>
{
System.Diagnostics.Debug.WriteLine("ItemsSource:", ItemsSource);
return new
NumberPage();
});
}
}
}
NumberPage.cs の記述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace TabPageDatabound01
{
public partial class NumberPage : ContentPage
{
public NumberPage()
{
this.SetBinding(ContentPage.TitleProperty,
"Name");
Label label = new Label
{
HorizontalOptions =
LayoutOptions.Center,
FontSize = 40
};
label.SetBinding(Label.TextProperty,
"Number");
this.Content = label;
}
}
}
App.cs の書き換え
App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace TabPageDatabound01
{
public class App : Application
{
public App()
{
// TabbedPageをMainとしてセットする
MainPage = new Main();
}
}
}
コメントをお書きください