0

I would like to have a few Content Pages , which I add in my MainPage class. I use SetLayout function to do that, which parameter is ContentPage. How to dock a ContentPage to my ContentPage( MainPage) as children please? My MainPage xaml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:MyApp.MainPage"
         x:Class="MyApp;assembly=App"
         BackgroundColor="White">
<StackLayout x:Name="Form">
</StackLayout>
And SetLayout function in MainPage.cs
private void SetLayout(ContentPage page)
    {
        if (LastControl != null)
        {
            LastControl.IsEnabled = false;
            Form.Children.Remove(LastControl);
            Form.Children.Add(page);
           
        }
        else
        {
            Form.Children.Add(page);
        }
        page.IsVisible = true;

        LastControl = page;
    }

In function above I have error on Form.Children.Add, because this wants contentview, not contentpage. I dont want to change my ContentPage to ContentView, because I want to have working BackButton.

Any idea? Thanks

locca
  • 7
  • 2
  • 1
    Take a look at this answer: https://stackoverflow.com/questions/30417671/xamarin-forms-can-i-embed-one-contentpage-or-contentview-into-another-contentpa – Dan Gerchcovich Aug 19 '20 at 10:22
  • Has StackLayout BackButton method? When I click on back button this just minimalize app, no go to previous page. – locca Aug 19 '20 at 11:35
  • If you want to use navigate function, Why not to use ` Navigation.PushAsync(page); Navigation.RemovePage(page);` following way to push or remove a page. – Leon Aug 20 '20 at 07:18
  • Parameter is Page, not View, so I cannot use this method. – locca Aug 20 '20 at 07:55
  • Do you want to achieve a pop up view like this plugin result? https://github.com/rotorgames/Rg.Plugins.Popup – Leon Aug 20 '20 at 09:47
  • I resolved this :) – locca Aug 20 '20 at 10:43
  • Please share your solution to answer, it will help others who have similar issue. – Leon Aug 21 '20 at 05:28
  • @LeonLu-MSFT I would like to have a lot of template pages of type ContentPage and then in one ContentPage , have function to use these templates, something like this.Children.Add for ContentViews – locca Aug 28 '20 at 08:29

0 Answers0