本文介绍了Xamarin表单:TabbedPage中的ContentPages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一些自定义内容页面放入选项卡式页面.遗憾的是,我不确定如何使用XAML语法执行此操作.我的虚拟项目如下所示:
I am trying to put some custom Content Pages into a Tabbed Page. Sadly I am not sure, how to do this with the XAML syntax. My dummy project looks like the following:
第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页完全相同.标签页:
Page 2 exactly the same. The Tabbed Page:
<?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>
页面将不会显示?我该如何正确执行此操作?
The Pages just won't show up? How can I do this properly?
推荐答案
您做错了.您必须将页面放置为TabbedPage子级.
You are doing it wrong.You must place the pages as the TabbedPage Children.
这是解决方案:
<?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>
或者,您也可以通过编程方式做到这一点:
In alternative you can do it programmatically:
public class TabsPage : TabbedPage
{
public TabsPage ()
{
this.Children.Add (new Page1 () { Title = "Home" });
this.Children.Add (new Page2 () { Title = "Browse" });
}
}
这篇关于Xamarin表单:TabbedPage中的ContentPages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!