WPF on Mac

This blog post delves into the evolving landscape of cross-platform UI development, specifically focusing on the transition of Windows Presentation Foundation (WPF) applications to macOS.

Mike James

How to run Windows Presentation Foundation (WPF) Applications on Mac

Developers seeking powerful UI frameworks with cross-platform capabilities often look for WPF-like solutions outside the Windows ecosystem. The goal is not only to replicate the rich user experience and robust functionality that WPF offers but also to ensure that these applications can thrive on platforms like macOS. The challenge here lies in finding a framework that balances the complex features of WPF with the flexibility required for cross-platform development.

In this post, we will explore how developers can leverage existing skills and codebases to run WPF applications on macOS, providing a pathway to broaden the reach of their applications while maintaining the high standards of performance and design that users expect.

Does WPF Have a Future?

WPF remains a strong choice for Windows-only development. However, those seeking a WPF-like development that can run on all popular platforms should be developing with Avalonia. 

WPF's powerful features have made it a favourite among developers who specialise in creating Windows applications. However, in an era where cross-platform development is not just a bonus but a necessity, questions about the future viability of WPF naturally arise. Those seeking a development experience similar to WPF but with the added benefit of running on all major platforms, including macOS, Linux, iOS, Android and Browser, should consider adopting Avalonia.

Avalonia is a powerful alternative to WPF, designed from the ground up to be cross-platform while offering a development experience that is very similar to WPF. If you're an expert with XAML and MVVM, you'll feel right at home developing apps using Avalonia. Its growing popularity reflects a shift in developer priorities towards powerful solutions running across operating systems.

For a more detailed analysis of the future of WPF, diving into technical specifics and industry trends, I recommend you read the recent post from our friends at SciChart. They have shared their expert opinions on the trajectory of WPF, providing an incredibly insightful and nuanced perspective on where it stands in the current tech landscape.

The future of WPF hinges on its capacity for evolution. In a rapidly advancing technological world, developers are keenly aware of the importance of investing in technology that will remain relevant. Unfortunately, Microsoft's apparent disinterest in further developing WPF has significantly impacted its perceived longevity and relevance. This is a crucial reason why Avalonia, our open-source UI toolkit, has grown in popularity. Frameworks like Avalonia are considered the future, offering developers a viable path to transition their WPF applications to newer, more versatile platforms. Avalonia promises to maintain the rich functionality and design flexibility that WPF developers are accustomed to and extends these capabilities across multiple operating systems.

Recognising the challenges associated with rewriting WPF applications for cross-platform compatibility, we developed Avalonia XPF. This innovative solution is a binary-compatible, cross-platform fork of WPF designed to minimise the effort required to bring existing Windows applications to new platforms. Avalonia XPF aims to bridge the gap between the reliable, familiar development environment of WPF and the pressing need for cross-platform functionality. It's an acknowledgement that while Avalonia is an excellent option for starting new projects with cross-platform needs in mind, the reality of software development often involves working within the constraints of existing codebases. Avalonia XPF represents a strategic compromise, offering a way forward for teams who find a complete rewrite daunting or impractical. 


How to Run WPF on Mac

It's possible to run WPF applications on Mac with little to no code changes using Avalonia XPF! We typically see trial users of XPF testing their WPF apps on Mac within a few hours! 

This is possible thanks to Microsoft making WPF open-source and using a permissive license. We were able to fork it and replace the low-level Milcore assembly with Avalonia. This means that Presentation Framework and Presentation Core remain largely untouched, enabling binary compatibility. 

Below, I'll walk you through the simple process of running a WPF app on your Mac! We'll use a very simple WPF for this sample, a WPF clone of the classic Minesweeper game. 

GitHub Sample

To get started, I'll clone the repo. 

git clone https://github.com/MikeCodesDotNET/minesweeper.git

Add a NuGet.config

We ship Avalonia XPF as a NuGet package, which requires adding our private nuget feeds to gain access. We'll do this by creating a NuGet.config file at the root of our solution. It'll include the following: 

<?xml version="1.0" encoding="utf-8"?>
    <clear />
    <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="xpf" value="https://xpf-nuget-feed.avaloniaui.net/v3/index.json" />
    <add key="avalonia-nightly" value="https://nuget-feed-all.avaloniaui.net/v3/index.json" />
      <add key="Username" value="license" />
      <add key="ClearTextPassword" value="<YOUR_LICENSE_KEY>" />

Load the solution

We're now ready to open the solution in our favourite IDE. JetBrains Rider has fantastic support for WPF and Avalonia and works incredibly well with Avalonia XPF. For this reason, we recommend developers adopt Rider! 

JetBrains Rider on Mac OS X WPF app

Immediately, it's clear that the project has errors because it's unable to resolve the 'Microsoft.NET.Sdk.WindowsDesktop' project SDK. To fix this, we'll replace the SDK with Avalonia XPF. To do this, we'll open the .csproj and replace the project SDK with: 

<Project Sdk="Xpf.Sdk/1.0.1-cibuild001124">

Update the TargetFramework

Avalonia XPF requires WPF apps to target NET6 or above. For this reason, we'll update the apps Target Framework to the latest NET8 runtime. 


Add the license key

The last change is to add our license key to the csproj for the executable. 

  <RuntimeHostConfigurationOption Include="AvaloniaUI.Xpf.LicenseKey" Value="<YOUR_LICENSE_KEY>" />

Run the app!

We're now ready to run our WPF app on macOS! 

Minesweeper WPF app on mac

Can I use WPF Controls on Mac?

The binary compatibility of Avalonia XPF enables 3rd party pro controls to work seamlessly on new platforms! We support Actpro, DevExpress, Infragistics, Syncfusion, Telerik and SciChart. We add more support on request from our customers, so the list of supported 3rd party controls grows every week! This means you can confidently support new platforms, knowing your vital third-party controls are compatible and maintaining the functionality and reliability your mission-critical applications demand.

Our commitment to expanding the ecosystem of supported third-party controls is relentless. Driven by feedback and requests from our user customers, we continuously work to ensure all controls work flawlessly with Avalonia XPF. As a result, the list of compatible third-party controls is ever-expanding, reflecting our dedication to providing a comprehensive solution that caters to the diverse requirements of modern software development.

To facilitate a seamless development experience, we maintain an up-to-date compatibility database accessible to all users. This database offers a transparent view of which professional controls are currently supported, allowing developers to plan and execute their cross-platform strategies with confidence. Should you find that a specific control your application relies on is not yet supported, we encourage you to get in touch. By simply dropping us a message with your request, you initiate a process of supporting the desired control into Avalonia XPF. This level of responsiveness and adaptability underscores our mission to deliver a robust cross-platform framework that does not compromise functionality, reliability, or the development experience.

WPF Alternative for Mac

If you're looking for an alternative, rather than taking your WPF app to Mac using Avalonia XPF, you should investigate Avalonia. Avalonia is our open-source UI framework, which AMD, JetBrains and Unity have adopted. It provides a WPF-like development experience but isn't a 1:1 clone and thus requires some modifications to your app.

How to modernise a WPF app

We provide two great options for those looking to modernise their existing WPF apps. Adopting Avalonia is entirely free, though it requires work to migrate. Avalonia XPF, on the other hand, is a commercial product which provides a seamless transition! 

If you're interested in taking your existing WPF applications cross-platform, we'll be happy to organise a call to discuss your project. With our diverse background in cross-platform development, we can help you decide which technology is right for you.