Modernizing .NETpad: Project Update (Premium)

New dialog work

Last week, a reader asked me why I wasn’t posting the source code for the .NETpad modernization work I’m working on and writing about. This is by design, but I didn’t explain this well (or at all). So that’s on me, apologies. This initial phase of the project is about me figuring out what I can do to modernize .NETpad given Microsoft’s unexpected, renewal of formal support for WPF. This change delighted me to no end: Of all the app frameworks I’ve used over the years, WPF is by far my favorite. And of the several .NETpad versions I’ve created, the WPF version is likewise my favorite.

So this is very exciting (to me, at least). But after announcing its sudden turnaround on WPF and then releasing the initial support in .NET 9 Preview 4 the week of Build 2015 back in May, Microsoft has been largely silent. I expected and hoped for new rounds of updated documentation and improvements to the basic Windows 11 theming support in WPF, but there’s been nothing. It’s almost three months later, Microsoft has since issued .NET 9 Preview 5 and 6, and we’re at the halfway point between the announcement and the final release of .NET 9 in November. But there is very little news, and no meaningful documentation of any kind, and Microsoft hasn’t updated WPF support in .NET 9 at all since May.

So I’ve plowed forward. I’ve reacquainted myself with WPF, C#, .NET, and Visual Studio. I’ve built the app, updated the app, ventured off into more side projects than I can count, and experimented with alternatives and add-ons that I could maybe use to add functionality that pure WPF doesn’t address. I’ve improved the code quality. I’ve been learning, basically, and my excitement at unexpected progress here and there has triggered more articles about this work than I’d expected to write during this phase of the project.

And that’s an important point. I am a writer, and so the articles I’ve written so far are in many ways me working through the problems I’m experiencing. But I am not a programmer, not a “real” or “professional” programmer anyway, and so I make mistakes. I go down the wrong path sometimes. I look at things from some high level, make assumptions, get some work done, and then realize I need to start over. And so I do. And this has happened many times over the summer. But I’m enjoying the work, enjoy flexing this muscle again. And I share it with you because it’s difficult for me not to, and maybe a handful of you enjoy it too. Also, I don’t see anyone out there writing about this topic at all. Maybe I’m filling a small void of some kind. I don’t know.

Regardless, I should have been more explicit about my plans. Though the truth is, they’re in flux. Here’s where I’m at.

The schedule: When

I have a rough schedule in mind thanks to the timing for .NET 9, which is a requirement to do this work: Microsoft will launch .NET 9, and thus formal WPF support for Windows 11 theming, on November 12, 2024 at its annual .NET Conf event. So my rough (and potentially fluid) schedule for modernizing the WPF version of .NETpad aligns with that. What I’ve been waiting on is more information from Microsoft–documentation of any kind, updates to the functionality, and so on–and since that’s not happened so far, I’ve just worked with what I have. As noted, I’ve made more progress than expected, but I’ve also made many mistakes. Two steps forward, one step back.

Part of the work I’ve done is to improve the quality of the code. This takes many forms and is limited, again, by me and my limits as a developer. There are basic issues I struggle with related to application state, and there are technologies that are central to WPF, like data binding and resources/theming support, that are core to this code quality improvement. I need to understand these things, and so I’ve been researching, reading, and experimenting with code. There is so much work to do there.

The project: What

Pragmatically, I also just want to finish the project, which involves determining what I can do to make .NETpad more like the modern Notepad in Windows 11. And to make this easier to understand–I can churn out words, obviously, but sometimes the message gets lost–I’ll just list out those things.

  • Tabs. Notepad–like File Explorer, Terminal, and Microsoft Edge–features a tabbed-based user interface that allows the user to access multiple (text) documents in a single app window. This is the most obvious difference between .NETpad and Notepad, and it’s the one I’ve struggled with the most, and for two reasons. First, I figured this would require a complete re-architecture of the app, with a complex and more sophisticated design. And second, the Windows 11 theming update to WPF has introduced additional complexity to the visual style of tabs as implemented by WPF. Between these two issues, I didn’t think I’d be able to figure something out with pure WPF, but I had a conceptual breakthrough on the first of those issues and now know I can make this work from a coding perspective (and this has the added benefit of improving the code, which I love, while not adding complexity). The style/theming issues, oddly, are thornier. I think I can get past that, however.
  • Windows 11 theming. The WPF update Microsoft announced back in May is really just about this decades-old framework formally supporting Windows 11 theming–light/dark mode, transparent backgrounds, accent colors, and so on–and that’s what it delivered in .NET 9 Preview 4. Unfortunately, Windows 11 controls are different sizes than their old-school Win32 equivalents, with different spacing and layouts. And that means that WPF app UIs that looked OK in Windows Vista, Windows 7, and Windows 8 don’t look right anymore in Windows 10 and 11 when those apps are updated to support the new theming. Developers thus have a lot of fit and finish work to do, in two key areas: The XAML code that describes the layout of controls in app windows and the resource dictionaries and other elements that developers use to define colors and other visual resources. Hand-coding XAML to create pixel-perfect renditions of modern control UIs and layouts is where my skills/strengths and ADHD intersect, and that work has gone well. But the resource dictionary stuff, tied to some weirdisms in how WPF handles control states (selected, non-selected, hover-over, and so on) requires more work.
  • Modern app patterns. This has come up throughout this project because our notions about what makes an app “modern” evolve over time, and Microsoft is adopting modern app patterns throughout its in-box apps in Windows 11 as it updates each in turn. For Notepad, these patterns include the use of in-app navigation instead of triggering pop-up sub-windows (dialog boxes, etc.) where possible, and the biggest example of this is its settings pane. The settings pane takes over the main app window when evoked, and then you return to the normal app view when you’re done configuring the app. You see this app pattern all over the place–Calculator, Clock, Paint, and many other Windows 11 in-box apps use it–but its use in Notepad is, of course, the most interesting to me. And so I wanted this interface for .NETpad, and I figured out a solution that I feel good about (even given the changes noted below). I don’t know “how” Microsoft implements these interfaces in its own apps, I just know that what I did is identical from a user experience perspective. Hopefully, that work is “done.”
  • Dialogs. Tied to the previous issue, Notepad displays fewer dialogs now than it used to. Given the way that Notepad’s settings interface looks and works, I figured that some of the newer dialog-like interfaces–its save confirmation dialog, Go to line dialog, Find/Replace dialog, and so on–were perhaps implemented in some modern Windows App SDK way tied to the Metro/UWP legacy. (Though I find it odd that this and other apps use old-school Win32-style File Open/Save as dialogs too.) I struggled to come up with ways to implement these interfaces without using custom dialogs, and then I realized I could approximate key interfaces like Save confirmation, Go to line, and Find/Replace similarly to my settings interface work. But in my research, reading, and experimentation, I had a breakthrough (of sorts) and I’m changing it yet again. I will be writing about that change soon, but this stands as a key reason why I haven’t provided much in the way of the code I’ve written so far. I will do that when I know the code is “final,” but for now, in this phase of the project, anything can change. And a lot has.
  • Unique .NETpad features. I added word count to .NETpad years before Microsoft added it to Notepad, and I still have some fun features like app scaling that Notepad lacks. In modernizing the app, I thought about which of these unique features would make it forward and which would have to go away. The big loss so far is my support for themes, which I added because WPF didn’t support the native OS theming capabilities that Microsoft first introduced in Windows 10. But now it does, and so .NETpad supports that too. I was able to keep my app scaling functionality–it even works with the settings UI, which is neat. Maybe when this is done, I can think about adding over new/unique features. And maybe even bring back the themes feature. But first things first.

The code: How

Once I figure out all the constituent points noted above–what I wish to achieve, how I wish to achieve it, and when I will be able to get that work done–I will document the modernization of .NETpad in a step-by-step how-to format over a series of articles, as I did for some previous .NETpad versions. It’s getting there, but that work is probably still a few months away. At the very latest, I’ll start writing it up in November, coincidental to the .NET 9 launch. But I’m still hoping for documentation and tech updates from Microsoft in the interim, and if this functionality gets better and/or is finalized before then, I’ll wrap things up on the work/experimental side and get to work on that series sooner.

When that series is done, I’ll post the “finished” version–it’s never really done, of course–to GitHub as well. Then this will become the new starting point for .NETpad going forward. And if Microsoft updates Windows or Notepad, or whatever, in the future, we can move forward with this new version of the app.

Hopefully, the above explanations make sense to anyone who actually cares about this work. Next, I’ll return to my previously scheduled update: I have made some major changes to this project, and like so much else that’s happened this summer, it came out of nowhere and took on a life of its own.

More soon!

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

Thurrott