Home > Enterprise >  How to integrate sideview in main view
How to integrate sideview in main view

Time:11-02

I have two views grid view and side view. I want to import my side view in grid view so I have added the namespace here and then I have set it in grid.

GridView code:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="GridDemo.View.GridView"
         xmlns:v="clr-namespace:GridDemo.View"
       >

<Grid RowDefinitions="auto,auto"
     ColumnDefinitions=".5*,.5*">
    <Label Text="Hello from grid view" Grid.Column="0" Grid.Row="0"/>
    <v:SideView Grid.Column="1" Grid.Row="1"/>
</Grid>

SideView Code:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="GridDemo.View.SideView"
         Title="SideView">
<VerticalStackLayout>
    <Label 
        Text="Welcome to .NET MAUI!"
        VerticalOptions="Center" 
        HorizontalOptions="Center" />
</VerticalStackLayout>

but it is not working. Is it correct way to achieve that? Or I am doing it wrong?

CodePudding user response:

I have test it on the android and mac platform, the sideview can be added into the Grid. According to the exception message:

page's parent must be a page

Maui is a cross-platform framework and the control in it is the different control in the different platform with the view handler. The ContentPage can't be added into the Grid as a child view on the windows platform.

But you can change the SideView's type as the contentview. Such as:

<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     x:Class="GridDemo.View.SideView">
<VerticalStackLayout>
    <Label 
        Text="Welcome to .NET MAUI!"
        VerticalOptions="Center" 
        HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
  • Related