News

.NET 6 Gets Blazor WebView Controls for WPF, WinForms

Along with initial support for Hot Reload functionality, the new .NET 6 Preview 3 also introduces BlazorWebView controls for Windows Presentation Foundation (WPF) and Windows Forms (WinForms) apps.

With the controls, developers can embed Blazor code into existing apps that run on .NET 6, a unifying, all-things-.NET umbrella framework going GA in November. It's a big milestone for Blazor, which debuted as a way to code web apps with C# without having to use JavaScript but is gradually being pointed at other targets, including mobile apps. Blazor Desktop has received a lot of attention in the Microsoft-centric developer space.

The WPF/WinForms BlazorWebView controls are being introduced in Preview 3 as part of Microsoft's plan to support cross-platform hybrid desktop apps in .NET 6 using .NET MAUI (.NET Multi-platform App UI), which is an evolution of Xamarin.Forms that adds desktop support.

"Hybrid apps are native apps that leverage web technologies for their functionality," said Microsoft's Daniel Roth, principal program manager, ASP.NET, in an April 8 blog post. "For example, a hybrid app might use an embedded web view control to render web UI. This means you can write your app UI using web technologies like HTML & CSS, while also leveraging native device capabilities. We will be introducing support for building hybrid apps with .NET MAUI and Blazor in an upcoming .NET 6 preview release."

For now, Roth's post explains how to use the BlazorWebView controls in both WPF and WinForms, with simple counter examples shown below just to prove they work, though numerous steps are required. Some developers already created other working examples, such as this BlazorDesktopWPF demo project that balked at adding Razor components, a problem fixed by Roth with a pull request.

A Blazor WinForms App
[Click on image for larger view.] A Blazor WinForms App (source: Microsoft).
A Blazor WPF App
[Click on image for larger view.] A Blazor WPF App (source: Microsoft).

"Using Blazor and a hybrid approach you can start decoupling your UI investments from WPF & Windows Forms," Roth continued. "This is a great way to modernize existing desktop apps in a way that can be brought forward onto .NET MAUI or used on the web. You can use Blazor to modernize your existing Windows Forms and WPF apps while leveraging your existing .NET investments."

As for two other much-requested features, Preview 3 adds initial Hot Reload support, but ahead-of-time (AoT) compilation is still on tap, with some potential drawbacks.

"WebAssembly AoT is coming in .NET 6 as well and it should be available in soon in an upcoming .NET 6 preview," said Roth in response to a reader question. "The performance improvements are looking really good! The tradeoff is a larger download size (~2x larger), a heavier toolchain (involves using Emscripten), and a longer publish time (minutes instead of seconds)."

Read Roth's post ("ASP.NET Core updates in .NET 6 Preview 3") for more, including:

  • Smaller SignalR, Blazor Server, and MessagePack scripts
  • Enable Redis profiling sessions
  • HTTP/3 endpoint TLS configuration
  • Razor compiler no longer produces a separate Views assembly
  • Shadow-copying in IIS
  • Vcpkg port for SignalR C++ client
  • Reduced memory footprint for idle TLS connections
  • Remove slabs from the SlabMemoryPool

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

Subscribe on YouTube