いくつかのカスタムコンテンツページをタブ付きページに入れようとしています。残念ながら、XAML構文でこれを行う方法がわかりません。私のダミープロジェクトは次のようになります。
ページ1
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.Microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Pages.Page1">
<Label Text="Page 1" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
2ページまったく同じです。タブ付きページ:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.Microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Pages.Navigation">
<ContentPage x:Class="MyApp.Pages.Page1" Title="Home">
</ContentPage>
<ContentPage x:Class="MyApp.Pages.Page2" Title="Browse">
</ContentPage>
</TabbedPage>
ページが表示されないだけですか?どうすればこれを適切に行うことができますか?
あなたはそれを誤解している。ページをTabbedPageの子として配置する必要があります。
解決策は次のとおりです。
<?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:mypages="clr-namespace:MyApp.Pages;Assembly=MyApp"
x:Class="MyApp.Pages.Navigation">
<TabbedPage.Children>
<mypages:Page1 Title="Home"/>
<mypages:Page2 Title="Browse"/>
</TabbedPage.Children>
</TabbedPage>
別の方法として、プログラムでそれを行うことができます。
public class TabsPage : TabbedPage
{
public TabsPage ()
{
this.Children.Add (new Page1 () { Title = "Home" });
this.Children.Add (new Page2 () { Title = "Browse" });
}
}
今日の日付のように、「Children」プロパティを追加する必要はありません。ページが別のディレクトリにある場合は、「PagesDirectory」と言います。以下のようにコンテンツページ「Page1」を参照できます。これは完全に正常に機能します。
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.Microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:YourApp.Views.PagesDirectory"
mc:Ignorable="d"
x:Class="YourApp.Views.TabbedPage"
Title="Tabbed Page">
<views:Page1 Title="Content Page 1"></views:Page1>
<views:Page2 Title="Content Page 2"></views:Page2>