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

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube