3

Is it possible to create common controls that can be used for both UWP and WPF applications?

Tried digging over the .NET and found out that code can be shared across them using .NET Standard but what about XAML controls/UI ?

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • There is [XAML Standard](https://blogs.windows.com/buildingapps/2017/05/19/introducing-xaml-standard-net-standard-2-0/#oiYgVCt33rbzouYU.97), however I'm not aware of its current state. An approach that has always worked is to have two library projects with different target platforms, but a common code base. Code parts that have to be different for each platform may be put into partial classes. I've successfully followed this approach in [XAML Map Control](https://github.com/ClemensFischer/XAML-Map-Control). – Clemens Jun 08 '18 at 07:13
  • 1
    Going forward with WPF apps that are running on Win10 OS, you can take a look at XAML islands ( https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/xaml-host-controls ). It allows UWP controls to be hosted inside WPF. – Depechie Jun 08 '18 at 11:18

1 Answers1

2

You can't directly use WPF controls in UWP apps, as there are many features of WPF XAML which are not yet available in UWP. So direct forward compatibility is not available here. Evenso, upgrading existing WPF controls to UWP should not be too hard, usually all it takes is to rewrite some parts of XAML but the actual business logic behind them can be ported 1:1, as most is covered by .NET Standard.

However, at Build 2018 Microsoft announced UWP XAML Islands functionality, that will allow developers to upgrade the UI of WPF apps to modern UWP design, including Fluent Design System features. In the near future you will be able to do this with all UWP controls (including custom), once the APIs are ready, but currently you can at least use the modern UWP WebView control in WPF, which is part of the Windows Community Toolkit.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91