Using Mica backdrop with UNO Platform applications
Recently a user asked in uno-platform's discord channel if the WinUIEx package works with Uno Platform. Morten Nielsen , the WinUIEx developer -(AKA dotMorten)- stated that it can only be used with Windows:
"WinUIEx is for use with WinUI/Windows. It’s not a cross platform api in any way. You can use it in Uno for windows targets only."
If you are interested in applying the Mica backdrop to the Windows head of an UNO application, I can show you a tip that worked for me. At the time of writing I was working with Uno Platform 4.7 and WinUIEx 1.8.0.
First of all add the WinUIEx package to the Windows project.
dotnet add package WinUIEx
--version 1.8.0
Important: If you have a background in your xaml covering the backdrop, i.e. a ShellPage with a NavigationView, be sure to set the background Transparent. If you need a different background color for the other platforms, you can use platform-specific C# code or platform-specific XAML markup. Let me thanks Marten for his advice about this specific point and for his great job with WinUIEx tools.
App.xaml.cs
Add a WinUIEx.WindowManager field:
#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
private WinUIEx.WindowManager _manager;
#endif
Next configure the WindowManager in OnLaunch() method:
#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
MainWindow = new Window();
_manager = WinUIEx.WindowManager.Get(MainWindow);
_manager.PersistenceId = "MainWindow";
_manager.Backdrop = new WinUIEx.MicaSystemBackdrop();
MainWindow.Activate();
#else
MainWindow = Microsoft.UI.Xaml.Window.Current;
#endif
And that's all, now you can run the Windows project and see the result.
Comments
Post a Comment