What is best approach to distribute a view in a class library(dll)?

Viewed 23

I have a class library(targeting .NET Standard 2.0) for someone else to consume, and I want to provide a view (using WebView2) so that the consuming app can display a web view. As far as I understand WebView2 has SDKs targeting different desktop application development options such as Win32, WPF & Windows Forms. How should I write my view once so that it will target and be compatible with all these different options? or is it even possible to do so?

In fact, after installing the WebView2 SDK in nuget in my class library project, I can't even import Microsoft.Web.Webview2 to start with... maybe it's because my class library's target platform?

1 Answers

If you don't show any UI other than the WebView2 and you only interact with the 'web' part of the WebView2, then you could allow your caller to give you their CoreWebView2. All the WebView2 UI controls have a CoreWebView2 property that returns the common CoreWebView2 type. Then it won't matter which UI framework they're using, nor will it matter how they host the WebView2, they'll be able to use your code.

If, on the other hand, you need to interact with the 'view' part of WebView2, then you'd need to write different code to handle the WPF WebView2 control, the WinForms WebView2 control, and the ICoreWebView2Controller from Win32.

Related