2

I created a sftabView, every SfTabItem have a ContentView so I created an other View to display it in this ContentView. so the question is how to make this happened? This is the ContentView which I wanted to display in the ContentPage

<?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>

and this is my ContentPage:

<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>
Gazdallah Amira
  • 188
  • 3
  • 16

2 Answers2

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

Explanation:

  • Add an xmlns:... definition for the namespace your ContentView is in.
  • Add an element with that namespace and the class name of your ContentView. <mynamespace:Self_Trainig ... />
  • ...: After the class name, you can add any needed attributes. Just like any other ContentView.
  • If you want your view to have "custom" attributes (as opposed to the standard attributes of ContentView such as BackgroundColor), that can be set in each page's XAML, then in your ContentView's code behind, you'll add BindablePropertys. Doing that correctly is beyond the scope of this answer; there are other Q&As on that topic.
ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
0

is it possible to display the view form the C# code ?

i mean doing

ContentView x:Name="TheView"

and on the C# code doing something like

TheView = Self_Trainig;

i know that code doesn't work but i'm searching that kind of solution

  • To do it with just C# code, you would need to set the 'Content' property: `this.Content = self_Trainig`. `self_Trainig` in this case would need be a instance of the ContentView control. – mamift Feb 14 '23 at 02:09
  • This does not look like an answer to the current question. If it is not an answer, please create a new question. You can always include a link in your question, back to this question, and mention how the two questions relate. – ToolmakerSteve Feb 14 '23 at 04:24