gpt4 book ai didi

c# - Xamarin 表格 : ContentPages in TabbedPage

转载 作者:太空狗 更新时间:2023-10-29 21:16:41 25 4
gpt4 key购买 nike

我正在尝试将一些自定义内容页面放入选项卡式页面中。遗憾的是,我不确定如何使用 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" });
}
}

关于c# - Xamarin 表格 : ContentPages in TabbedPage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37744472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com