Dreamescaper / BlazorBindings.Maui

MAUI Blazor Bindings - Build native and hybrid MAUI apps with Blazor
MIT License
253 stars 23 forks source link

Error on adding component to an element #57

Closed AmirImam closed 2 years ago

AmirImam commented 2 years ago

Hi This line of code throws an exception

[Inject]
private MauiBlazorBindingsRenderer Renderer { get; set; }

    protected override async void OnAfterRender(bool firstRender)
    {
        if (firstRender is true)
        {
            ContentPage page = new() { Title = "Ref" };
            await Renderer.AddComponent<MainPage>(page); //Error here
        }
    }

Exception is image

MainPage is a ContentView I tried to make it a ContentPage but it throws the same error I tried this on windows & android

Dreamescaper commented 2 years ago

Yeah, seems like I've accidentally broken it for other controls (apart from Application). I'll try to fix it soon.

I'm wondering though - what is your use case? Why do you add content to a page inside of other Blazor component?

AmirImam commented 2 years ago

I want to use NavigationPage to navigate between pages, and I want to set this NavigationPage to the Details of a FlyoutPage. I have always designed my classic XF apps like this, and I want to try it here

Dreamescaper commented 2 years ago

I see.

As a temporary workaround (until I fix this issue), you can retrieve a page via smth like this (your main page should have ContentPage as a root element):

        var rootContainer = new RootContainerHandler();
        await Renderer.AddComponent<MainPage>(rootContainer);
        var page = (MC.Page)rootContainer.Elements[0];

Also, you can take a look at a FlyoutPage sample, it makes it work without Renderer interaction: https://github.com/Dreamescaper/BlazorBindings.Maui/blob/main/samples/FlyoutPageSample/Views/MainPage.razor .

AmirImam commented 2 years ago

I see.

As a temporary workaround (until I fix this issue), you can retrieve a page via smth like this (your main page should have ContentPage as a root element):

        var rootContainer = new RootContainerHandler();
        await Renderer.AddComponent<MainPage>(rootContainer);
        var page = (MC.Page)rootContainer.Elements[0];

Also, you can take a look at a FlyoutPage sample, it makes it work without Renderer interaction: https://github.com/Dreamescaper/BlazorBindings.Maui/blob/main/samples/FlyoutPageSample/Views/MainPage.razor .

Thank you, this workaround worked fine. I think that I can't test FlyoutMenuPage yet, did you release it?

Dreamescaper commented 2 years ago

FlyoutMenuPage and FlyoutMenuItem are parts of that same sample https://github.com/Dreamescaper/BlazorBindings.Maui/tree/main/samples/FlyoutPageSample/Views

Dreamescaper commented 2 years ago

Bugfix was merged, and will be released soon (-ish), therefore I'm closing this item. If you'd like, you can check it out in the nightly builds (read here).