xamarin 如何在内容页中显示内容视图

hkmswyz6  于 2023-02-14  发布在  其他
关注(0)|答案(2)|浏览(138)

我创建了一个sftabView,每个sfTabItem都有一个ContentView,所以我创建了另一个View来在这个ContentView中显示它。所以问题是如何实现这一点?这是我想在ContentPage中显示的ContentView

<?xml version="1.0" encoding="utf-8" ?>
<ContentView    
    xmlns="http://xamarin.com/schemas/2014/forms"
    x:Class="App5.Views.Self_Trainig"

    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  
    NavigationPage.HasNavigationBar="False">

    <ContentView.Resources>
        <ResourceDictionary>
    ............
        </ResourceDictionary>
    </ContentView.Resources>

    <ContentView.Content>
        <AbsoluteLayout>
...............
        </AbsoluteLayout>

    </ContentView.Content>
</ContentView>

这是我的内容页:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:tabView="clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms"
             x:Class="App5.Views.Accueil">
    <ContentPage.Content>
        <tabView:SfTabView OverflowMode="DropDown" VisibleHeaderCount="3" BackgroundColor="White">
            <tabView:SfTabItem Title="Self Training">
                <tabView:SfTabItem.Content>
""the code to display it here""
                </tabView:SfTabItem.Content>
            </tabView:SfTabItem>

            <tabView:SfTabItem Title="Contacts">
                <tabView:SfTabItem.Content>
                    <Grid BackgroundColor="White" x:Name="ContactsGrid" />
                </tabView:SfTabItem.Content>
            </tabView:SfTabItem>

        </tabView:SfTabView>
    </ContentPage.Content>
</ContentPage>
smdncfj3

smdncfj31#

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:mynamespace=clr-namespace:App5.Views" 
    ...>
...
    <tabView:SfTabItem.Content>
        <mynamespace:Self_Trainig ... />
    </tabView:SfTabItem.Content>

说明:

  • 为ContentView所在的命名空间添加xmlns:...定义。
  • 添加具有该命名空间和ContentView.<mynamespace:Self_Trainig ... />类名的元素
  • ...:在类名之后,可以添加任何需要的属性,就像其他ContentView一样。
  • 如果您希望视图具有"自定义"属性(与ContentView的标准属性(如BackgroundColor)相反),这些属性可以在每个页面的XAML中设置,那么在ContentView的代码后面,您将添加BindableProperty。正确执行这些操作超出了本答案的范围;还有其他关于这个主题的问答。
lymnna71

lymnna712#

可以用C#代码显示视图吗?
我的意思是
内容视图x:名称=“TheView”
在C#代码上做一些类似于
视野=自我训练
我知道代码不起作用,但我正在寻找这种解决方案

相关问题