jspuij / TwokaB

Blazor WebView control for WPF, Android, macOS, iOS. Run Blazor on .NET Core and Mono natively inside a Webview.
https://jspuij.github.io/BlazorWebView.Docs/pages/index.html
Apache License 2.0
132 stars 16 forks source link

BlazorWebView bridge #21

Closed am-kh closed 4 years ago

am-kh commented 4 years ago

hi jspuij, Thank you for this control. Is it possible to have a bridge which transmits messages/data between Blazor and the native code of the platform? Blazor <-> WPF Blazor <-> Xamarin

Thank you for your help.

musictopia2 commented 4 years ago

I would think that would not be necessary. Because the razor class library can access the file system like normal. They can actually write to sql server. However, another choice can be to also use event aggregation. That would probably be the best way. So in the blazor, you can send a message and the wpf can pick it up and do things with it.

jspuij commented 4 years ago

There indeed is no bridge necessary. You're just running a full framework. So you can immediately access the WPF and Xamarin parts. The only thing that you have to be careful about is that Blazor is running on it's own thread that is NOT the desktop UI thread. (this is because there already is so much happening on the UI thread and there is a Javascript interop boundary anyway, so it was easier to just have a dedicated thread for the Blazor rendering).

So if you want to do something on the WPF or Xamarin UI, use the WPF or Xamarin dispatcher to schedule the operation. If you want to do something on the Blazor UI, use the Blazor Dispatcher to schedule the operation.