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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events