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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube