获取异常Java.Lang.IllegalArgumentException:只能将TabItem实例添加到xamarin表单中的TableLayout中
我得到了一个例外获取异常Java.Lang.IllegalArgumentException:只能将TabItem实例添加到xamarin表单中的TableLayout中,xamarin,xamarin.forms,tabbedpage,Xamarin,Xamarin.forms,Tabbedpage,我得到了一个例外 Java.Lang.IllegalArgumentException: Only TabItem instances can be added to TabLayout 这是我的XAML代码- <?xml version="1.0" encoding="utf-8" ?> <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://sch
Java.Lang.IllegalArgumentException: Only TabItem instances can be added to TabLayout
这是我的XAML代码-
<?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:pages="clr-namespace:RestaurantApp"
x:Class="RestaurantApp.SearchTabbedPage">
<!--Pages can be added as references or inline-->
<TabbedPage.Children>
<NavigationPage Title="VENDOR NAME">
<x:Arguments>
<pages:TabbedPageExampleTab1 />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="PRODUCT/SERVICE">
<x:Arguments>
<pages:TabbedPageExampleTab2 />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
这是app.xaml.cs代码
public App()
{
InitializeComponent();
MainPage = new SearchTabbedPage();
//};
}
这是TabbedPageExampleTab1的xaml代码
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RestaurantApp.TabbedPageExampleTab1">
<ContentPage.Content>
<StackLayout>
<Label Text="Hello. I am Judson" Margin="5" />
<Label Text="You are on Tab one"></Label>
<BoxView VerticalOptions="FillAndExpand" Color="Silver"></BoxView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
TabbedPageExampleTab2也遵循同样的代码
这就是我需要的用户界面
我不知道为什么会出现这个异常。任何建议。
使用此代码在
选项卡页面中添加页面
<?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:pages="clr-namespace:RestaurantApp"
x:Class="RestaurantApp.SearchTabbedPage">
<TabbedPage.Children>
<NavigationPage Title="VENDOR NAME">
<x:Arguments>
<pages:TabbedPageExampleTab1 />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Product/Service">
<x:Arguments>
<pages:TabbedPageExampleTab2 />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
编辑:您的Tabbar.xaml文件应该如下所示
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="@android:color/white"
app:tabGravity="fill"
app:tabMode="fixed">
</android.support.design.widget.TabLayout>
不要在它里面添加
TextView
。我认为这里是Children.add(newcontentpage())代码>,你应该添加ContentPage
键入Page1
或employeepage
等内容,而不是直接添加ConentPage
是的,我也试过了,我会编辑代码后面的代码你需要在TabbedPage中添加多少页,你能提到那些有问题的名字吗,比如我需要添加Page1,page2等@CGPA6.4我已经提到了TabbedPageExampleTab1,但它仍然给了我同样的例外。你不应该在SearchTabbedPage.cs
中再次添加Tab。您的页面TabbedPageExampleTab1
或TabbedPageExampleTab2
应该与ContentPage
一起继承。是的,我也这样做了。我现在将输入我的最新代码。下面的选项卡是您可以看到的选项卡PageExampleTab1和选项卡PageExampleTab2,我已将选项卡式页面设置为初始页面,您可以在我的app.xaml.cs代码中看到。如果可能,请提供我的项目zip存储库。好让我看看到底发生了什么。
<?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:pages="clr-namespace:RestaurantApp"
x:Class="RestaurantApp.SearchTabbedPage">
<TabbedPage.Children>
<NavigationPage Title="VENDOR NAME">
<x:Arguments>
<pages:TabbedPageExampleTab1 />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Product/Service">
<x:Arguments>
<pages:TabbedPageExampleTab2 />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
Children.Add(new TabbedPageExampleTab1());
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="@android:color/white"
app:tabGravity="fill"
app:tabMode="fixed">
</android.support.design.widget.TabLayout>