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.

Native components inside of web components

See original GitHub issue

Hi, first of all, great job 😃

The post came out a bit long and disorganized, so here is TLDR:

  • Template does not work in Rider, but does work in VS (kind of)
  • Can I mix Web and Native components? Will I be able to with MAUI?
  • How does the CounterState sample work? Is it the same object within the BlazorWebView and hosting app or is a copy kept in sync?
  • Is there a way to “hide” the fact that part of the app is HTML? I’m talking about context menu, back with mouse button etc

I got super excited about this whole thing, because in my mind I could just replace WPF app with a Blazor Hybrid, hosted in a BlazorWebView. Sounds great.

However, I spun up the template aaand… Under Rider it opens, but the web view never loads. When I run the app just from bin directory, it works, in VS it also works, but VS starts showin errors after clicking around without modyfing anything, but it still compiles and runs fine. Both Rider and VS updated today, but that’s really irrelevant.

image

First thing I wanted to try was to put a “native” component inside of web razor component, so I wrote:

@page "/nativetest"

<h3>NativeTest</h3>

<img src="http://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"/>

<StackLayout>
    @*<Entry @bind-Text="Text"/>*@
    @if (GoogleLogo != null)
    {
        <p>Second Google logo</p>
        <Image Source="GoogleLogo"/>
    }
    else { 
        <p>Second logo is null</p>
    }
</StackLayout>

@code {
    string Text { get; set; }
    ImageSource GoogleLogo { get; set; }

    protected override void OnInitialized()
    {
        GoogleLogo = ImageSource.FromUri(new Uri(@"http://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"));
        StateHasChanged();
    }
}

The result is not exactly what I expected: image

I imagine that getting this to work in Xamarin.Forms will be super hard, but how about MAUI? Is there even consideration for this?

My thought process is that I would love to write the whole app as HTML with CSS, and then maybe a small piece would be much better in a native form (can’t come up with a good example right now, but maybe some libs like CadLib would provide MAUI component for viewing and manipulating DXFs?). That would mean that I have to do the whole app natively, which would not be that bad, but I loose CSS.

I get that there will be some kind of styling system later, but will that make the whole hybrid thing obsolete?

Also, I have a question about the sample. Does Blazor use the CounterObject, as in it’s the EXACT same object in memory? Or is it a copy kept in sync?

Last thing, is there a default way to disable BlazorWebView default controls like right click context menu, go back with side mouse button etc?

I’m sorry for the unorganized gibberish, I just got super excited about the concept, but trying it spawned tons of questions.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Dreamescapercommented, Mar 3, 2021

The errors you see in VS are design-time only errors and don’t affect the operation of the program. The root bug is logged here: dotnet/aspnetcore#26647 For now you can ignore those errors (I don’t know of any way to make them go away; they’re just annoying!).

Personally I simply added namespace alias (@using XF = Xamarin.Forms) to workaround this issue. I need to add XF qualifier to all Xamarin.Forms arguments (e.g. XF.FontAttributes, XF.Color, etc) though…

1reaction
Dreamescapercommented, Mar 4, 2021

I think that it will be same as in Xamarin.Forms (considering that MAIU is basically a rebranded XF). https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/css/

Read more comments on GitHub >

github_iconTop Results From Across the Web

An Introduction to Native Web Components
Native browser web components provide a way to create encapsulated, single-responsibility, custom functionality that can be used with or without ...
Read more >
Web Components - Web APIs - MDN Web Docs - Mozilla
Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated ...
Read more >
How to create a Native Web Component without ...
Learn how to build native Web Components with HTML, CSS and JavaScript by our expert Patrick Jahr. Including sample code.
Read more >
Introduction - webcomponents.org
Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in...
Read more >
Web Components: A Native Component Model for UI
In this article we will talk a bit about web components, what they are, why they are used, who is using them, and...
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