question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shell menu not render

See original GitHub issue

Hi, I have an application that has a login page without a menu that, after the login logic takes the user to a page with the side menu.

So I have created the first page like this:

return new Shell() {
                new ContentPage()
                {
                    new VStack {
                        new Button("go to shell").VCenter().HCenter().OnTapped(goToSecond)
                    }
                }
            }.BackButtonIsVisible(false);

and the second page:

public override VisualNode Render()
            => new Shell
            {
            new FlyoutItem("Page1")
            {
                new ContentPage("Page1")
                {
                    new Label("PAGE 1").VCenter().HCenter().FontSize(50)
                }
            },
            new FlyoutItem("Page2")
            {
                new ContentPage("Page2")
                {
                    new Label("PAGE 2").VCenter().HCenter().FontSize(50)
                }
            }
            }
            .BackButtonIsVisible(false)
            .ItemTemplate(RenderItemTemplate);

        static VisualNode RenderItemTemplate(MauiControls.BaseShellItem item)
            => new Grid("68", "*")
            {
            new Label(item.Title)
                .VCenter()
                .Margin(10,0)
            };

If I set the first page as “main page”, then click on the button, the second page is open but without the shell side menu. If I set the second comage as “main page” the shell menu is rendered correctly.

How can I fix this?

Attached a sample.

Thank you MauiTest.zip

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adospacecommented, Jun 26, 2023

It’s an issue/feature of the shell control in MAUI. Pages are always cached (at least in current version) (https://github.com/dotnet/maui/issues/9300).

One solution could be handling the OnNavigated() event on the shell or the OnAppearing() event on child page and modify the page state accordly.

For example you could add .OnAppearing(()=> SetState(s => s.Title = 0)) on SecondPage

1reaction
adospacecommented, Jun 23, 2023

Well, it is more like a .NET MAUI issue, I mean, not an issue, probably more like which strategy to use to present a content page before a Shell. Surely there are more options but one could be using the Window, with a code like this (not tested):

public override VisualNode Render()
{
    return new Window
    {
        !State.LoggedIn ? 
        RenderLogin()
        :
        RenderShell()
    };
}

VisualNode RenderLogin()
{
      return new ContentPage()
      {
          new VStack {
              new Button("go to shell").VCenter().HCenter().OnClicked(()=>SetState(s => s.LoggedIn = true))
          }
      }
}

VisualNode RenderShell()
{
            return new Shell
            {
            new FlyoutItem("Page1")
            {
                new ContentPage("Page1")
                {
                    new Label("PAGE 1").VCenter().HCenter().FontSize(50)
                }
            },
            new FlyoutItem("Page2")
            {
                new ContentPage("Page2")
                {
                    new Label("PAGE 2").VCenter().HCenter().FontSize(50)
                }
            }
            }
            .BackButtonIsVisible(false)
            .ItemTemplate(RenderItemTemplate);
}

static VisualNode RenderItemTemplate(MauiControls.BaseShellItem item)
    => new Grid("68", "*")
    {
    new Label(item.Title)
        .VCenter()
        .Margin(10,0)
    };
}

Anyway I’ll take a look at your sample to see if there is anything wrong with MauiReactor/.NET MAUI

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Menus doesn't render in Shell if not part of Shell #5210
If I put menus on a ContentPage that is a FlyoutItem, then the menu renders. image. However, if I navigate to a page...
Read more >
menu items either do not load or render invisible [Windows ...
Steps to reproduce the behavior: Run Open Shell. Click or press on the Windows button to bring up the start menu. See error....
Read more >
Shell Flyout Menu not showing all the Menu Items ...
I am working with App Shell Menu Flyout to display menu items, but the menu item all are not showing all the times....
Read more >
Xamarin iOS Shell FlyoutMenu not rendering correctly
Xamarin iOS Shell FlyoutMenu not rendering correctly ... I am using Shell in my App to handle navigation between views and its FlyoutMenu ......
Read more >
Unable to copy from shell
I usually run a script, then right click | copy. but that option no longer appears for text highlighted in the shell window....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found