dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

ContentPage to have a BlazorWebView for HTML usage #412

Open johnmangam opened 2 years ago

johnmangam commented 2 years ago

Since Shell's Tab is expecting a ContentPage as a ShellContent, I was wondering if this is a valid way using BlazorWebView as ChildComponent so that I could use HTML as shown below.

  <ContentPage>
     <StackLayout>
            <BlazorWebView>
                <ProductItem></ProductItem>
            </BlazorWebView>
            <Label class="mylabel" Text="some text"></Label>
        </StackLayout>
</ContentPage>

ProductItem.razor

@page "/productitem"
<div>
    <h1>some heading text</h1>
</div> 

There is no error, but ProductItem is not seen.

Eilon commented 2 years ago

Yes, in theory this should work, but maybe you're missing some parameters on the <BlazorWebView ...> tag? Is ProductItem a Razor component?

johnmangam commented 2 years ago

Thank you @Eilon. Yes, here is the code of ProductItem that I'm trying to use in a BlazorWebView.

ProductItem.razor

@page "/productitem"
<div>
    <h1>some heading text</h1>
</div> 

Does the BlazorWebView expect something else, please?

johnmangam commented 2 years ago

I found a sample: https://github.com/dotnet/MobileBlazorBindings/blob/eaee277ee15fd3ef20f465c213bf6cd840023336/samples/HybridMessageApp/HybridMessageApp/MainPage.xaml

I will try, thank you @Eilon

johnmangam commented 2 years ago

Good morning @Eilon

Looks like the BlazorWebView has no Host property yet in order to get the HTML working. Could you confirm?

Thank you.

johnmangam commented 2 years ago

O, sorry @Eilon I have just now come across BlazorWebView\<IComponent> and MobileBlazorBindingsBlazorWebView that have Host property.

Perhaps, this is the way to go about it to get it working.

Thank you.

johnmangam commented 2 years ago

Sorry @Eilon I couldn't get this working.

I would appreciate it if you or your team could provide a tiny code snippet to get this working.

In a Shell, ShellContent is a ContentPage where I want to have a BlazorWebView to show razor with HTML.

Thank you.

johnmangam commented 2 years ago

@Eilon

I got hold of passing the Host, but ContentPage is null here, could you let me know where I should be setting this? Thank you.

image