Can I create my own page layout using Xamarin.Forms?

What I would like to achieve is a bit like this

enter image description here

Where "some kind" is some custom content (both page and content) that is fixed and never changes (like the status bar) and the page will change with normal navigation (via NavigationPage).

I already have something similar, but "some view" is recreated every time the user navigates, because each page comes from a base page containing "some view".

public sealed class RootPage : ExtendedMasterDetailPage
{
    public RootPage()
    {
        // 30%
        DrawerWidth = .3f;
        Master = new MenuPage();
        Detail = new NavigationPage(new HomePage());
    }
} 

public abstract class MasterPage : ContentPage
{
    private readonly Grid _root;
    private View _content;

    // Subclasses set this property to add their content
    public View Detail
    {
        get { return _content; }
        set
        {
            if (_content != null)
                _root.Children.Remove(_content);
            _content = value;
            if (_content != null)
                _root.Children.Add(_content, left: 0, top: 1);
            OnPropertyChanged();
        }
    }

    protected MasterPage()
    {
        _root = new Grid
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            RowDefinitions =
            {
                new RowDefinition {Height = new GridLength(60, GridUnitType.Absolute)},
                new RowDefinition {Height = new GridLength(1, GridUnitType.Star)},
            },
            RowSpacing = 0
        };

        // BuildStatusBar() creates the "static" content that is placed above the page
        _root.Children.Add(BuildStatusBar(), left: 0, top: 0);

        Content = _root;
    }
}

public sealed class HomePage : MasterPage
{
    public HomePage()
    {
        // Build content
        Detail = ...
    }
}

      

In this blog post, the author does something similar to me, but in XAML, and it seems to him that his content is reloaded every time; whereas I only want the content page to change and the title "some view" stays there.

I believe I need some kind of custom renderer and the best documentation on this looks like this one to update your own renderer . However, I cannot figure out how to apply it to my scenario.

+3


source to share


1 answer


I don't think you can achieve this in Xamarin.Forms.



You can change the content of the content in it using animation , but that would not be the right solution. Impossible (or too much effort) to get back through the hardware keys.

0


source







All Articles