Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

BlazorWebView interaction #417

Open
ghost opened this issue Oct 10, 2021 · 1 comment
Open

BlazorWebView interaction #417

ghost opened this issue Oct 10, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 10, 2021

This is not completely related to BlazorMobile bindings, But I created a windows forms app and then render a razor component inside BlazorWebView control:

`BlazorWebView blazorApp = new BlazorWebView()
 {
     Dock = DockStyle.Fill,
     HostPage = "wwwroot/index.html",
     Services = serviceProvider 
 };
 blazorApp.RootComponents.Add<App>("#app");
                
 var form1 = new Form1();
 form1.Controls.Add(blazorApp);
 Application.Run(form1);`

To create a good hybrid app that uses both blazor and win forms, I need to interact between blazor component inside BlazorWebView and Form1, So that I can send data to or call component public methods from Form1 and recieve notifications from the component back to Form1, But I can't find a suitable member in the BlazorWebView's list of members to do this. Is there any way to do this?

@Eilon
Copy link
Member

Eilon commented Oct 12, 2021

@mg1357 , in general the way to do this is so define a "service" in the Dependency Injection (DI) container and then use that service from both the Blazor UI using the @inject directive, and also from the native UI (WinForms/WPF/etc.).

You can learn more about DI here: https://docs.microsoft.com/mobile-blazor-bindings/advanced/dependency-injection

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant