.netpad Modernizing .NETpad: .NET 9 Arrives with a Few (More) Small Improvements for WPF (Premium) By www.thurrott.com Published On :: Tue, 12 Nov 2024 17:14:34 +0000 I was excited to see Microsoft bring the Windows Presentation Foundation (WPF) back from the dead this past year: At Build 2024 back in May, it announced that it would continue investing in this 20-year-old technology, starting with support for Windows 11 theming that would arrive as part of .NET 9. In fact, I was so excited about this that I brought my .NETpad project back from the dead as well, and I spent much of the summer modernizing my Notepad clone with the new features. I wrote 24 articles documenting this work, but I was stymied by the half-assed nature of the improvements. Microsoft released exactly one WPF update during the several months of .NET 9 development, and it never added any of the features I discovered were missing. And so as we headed into today's release of .NET 9, my excitement was somewhat diminished. My assumption was that we wouldn't see those missing features implemented until .NET 10, if ever. Well, Microsoft just released .NET 9. As part of that release, it published updated documentation for WPF (and all the other .NET technologies). And to my surprise, there are some updates to WPF that address at least one of those missing features. So let's take a look. To add support for Windows 11 theming to a WPF project, you need to add a reference to the new Fluent theme resource dictionary in its App.xml file. It looks like so: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> But with the shipping version of .NET 9, there's a second, more elegant way to add Windows 11 theming support. Now, you can access a new Application.ThemeMode property of a new styling API to toggle the app's theme mode between Light, Dark, System, and None. And that's fantastic, because it addresses one of those missing features: To date, .NETpad has adapted itself to the system theme (Light or Dark), but there was no way to let the user pick a theme mode. (For example, if the system was set to Dark and the user wanted the app to use Light mode.) With this change, I can implement that feature. Fortunately, .NETpad is ready for this change, too: If you followed along with my work this past summer, you may remember that I implemented the user interface for switching the app theme into its settings interface, but left the UI hidden because it didn't do anything. But I always felt that Microsoft would need to implement this features, so I left the code in there. Granted, I didn't think it would happen this quickly. The shipping version of .NET 9 also adds explicit support for the Windows 11 accent color (as configured by the user in the Settings app in Personalization > Accent color). As it is, .NETpa... The post Modernizing .NETpad: .NET 9 Arrives with a Few (More) Small Improvements for WPF (Premium) appeared first on Thurrott.com. Full Article Dev Premium .NETpad WPF Windows Presentation Foundation Modernizing .NETpad (2024)