Modernizing .NETpad: It’s a Wrap (Premium)

It took 7 months, but today I finished coding my 2024 .NETpad modernization project. I also found another bug in WPF Windows 7 theming support. Of course I did.

So let's start there.
A new bug
When Microsoft released .NET 9 in November, I was surprised to discover that it included a few small but important updates. Key among them was the ability to switch the app theme on the fly, a basic feature that was missing from the Windows 11 theming capabilities Microsoft had previously made available to developers during the .NET 9 pre-release development period. Until that change, you could make an app that conformed to whatever theme the user chose in Windows 11 Settings, and it would change on the fly if the user changed that theme. But there was no way to manually select a theme. For example, if the system theme is set to Dark but you (or the user) want to use the app in Light mode.

Most modern Windows 11 apps support this feature. So, too, does Notepad. And I was sure that it would come to WPF at some point. In fact, I was so sure that I wrote the UI code for this interface in XAML, but left it grayed out since there was no way to change it on the fly. Here's how it looks.

As I wrote in Modernizing .NETpad: .NET 9 Arrives with a Few (More) Small Improvements for WPF (Premium), Microsoft implemented this capability using a new Application.ThemeMode property in the styling API. And it's quite easy to use: I spun up a quick sample project in Visual Studio and created a button that toggled between Light, Dark, and System themes (the latter of which will be either Light or Dark, depending on what the user configures). Couldn't be easier.

But when I added this code to .NETpad and tried to change the app theme, it would crash with an unhandled exception. I have multiple versions of the app, each a little different, so I tried it in three of them. But I always had the same issue. Whenever I changed the theme on-the-fly, the app crashed. Fantastic.

Because I was winding down this project, I decided to not worry about it: I would add this feature early in a clean, new version of the app and then, once I had it working, I'd build it out and keep checking on this toggle to see when (or whether) it started crashing so I could hopefully isolate the problem. I wrote about this a bit in Modernizing .NETpad: WTF, WPF (Premium), in which I also discussed another small but important addition to the Windows 11 theming support in WPF in .NET 9, the new accent color support for the default button in dialogs. That feature, at least, seems to work fine, and I've implemented it in all the recent versions of the app I've worked up.

But then I got side-tracked a bit. Experimenting on the side, I started getting the long-awaited tab support (and related window title bar customization) working. And so I started to think about, and then implement, the code that would be necessary to transition .NETpad from supporting a single document to one th...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC