Created
          March 8, 2023 18:44 
        
      - 
      
- 
        Save jfversluis/226efd350fde6cceb28286ae8ef2327c to your computer and use it in GitHub Desktop. 
    Use the new Windows App SDK Backdrop API in .NET MAUI
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using Microsoft.Extensions.Logging; | |
| using Microsoft.Maui.LifecycleEvents; | |
| #if WINDOWS | |
| using Microsoft.UI.Xaml.Media; | |
| #endif | |
| namespace MauiApp1; | |
| public static class MauiProgram | |
| { | |
| public static MauiApp CreateMauiApp() | |
| { | |
| var builder = MauiApp.CreateBuilder(); | |
| builder | |
| .UseMauiApp<App>() | |
| .ConfigureFonts(fonts => | |
| { | |
| fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); | |
| fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); | |
| }); | |
| #if WINDOWS | |
| builder.ConfigureLifecycleEvents(events => | |
| { | |
| // Make sure to add "using Microsoft.Maui.LifecycleEvents;" in the top of the file | |
| events.AddWindows(windowsLifecycleBuilder => | |
| { | |
| windowsLifecycleBuilder.OnWindowCreated(window => | |
| { | |
| window.SystemBackdrop = new DesktopAcrylicBackdrop(); | |
| }); | |
| }); | |
| }); | |
| #endif | |
| #if DEBUG | |
| builder.Logging.AddDebug(); | |
| #endif | |
| return builder.Build(); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment