The WPF Notepad Project (2022): Reviving My Favorite .NETpad (Premium)

For my March programming project, I’m reviving the Windows Presentation Foundation (WPF) version of .NETpad, which is my favorite version of the app. As with the Windows Forms version, I’ll make this project available on GitHub so that others can fork the project and customize it as they’d like.

As you may recall, the WinForms version of .NETpad required a lot of work before I could make it available publicly on GitHub. But that’s not the case with the WPF version: thanks in part to its more modern framework---albeit one that is still over 15 years old---this version makes a much easier transition to this .NET 6-based world. The source code also looks cleaner, and it thankfully offers more in the way of comments-based documentation.

As with the WinForms version of .NETpad, I started by using Visual Studio 2022 Community to clone my GitHub repository, in this case for NotepadWPF, as the project is called. A notification noted that the version of .NET used by this project---.NET Core 3.1---was not available on this PC and offered to install it. But I wanted to upgrade it to the latest .NET version, .NET 6, anyway. And when I opened the project’s Properties interface, I was delighted to see I could simply choose .NET 6 from the Target framework drop-down: doing this with a WinForms app requires you to use the error-prone .NET Migration Tool, which I never got to work correctly.

With that out of the way, I built and ran the app and encountered no issues at all. Out of the box, so to speak, the WPF version of .NETpad just worked normally, unlike its WinForms cousin.

This allowed me to immediately look at implementing the fixes I made in the WinForms version of .NETpad before publishing it to GitHub.

But I was initially surprised to see that one of those bugs---the maximize bug, as I called it---wasn’t even present in the WPF version of the app: if you maximize the app, close it, and restart it, it remembers that it was maximized. At first, I thought that this was perhaps a built-in WPF feature, but no: I had, in fact, written code in the AppWindow_Initialized() event handler to address this need; I had just forgotten:
if (Settings.Default.MyMaximized == true)
AppWindow.WindowState = WindowState.Maximized;
else
AppWindow.WindowState = WindowState.Normal;
I guess this makes sense: the WPF version of the app does have several improvements over the WinForms version. This was one I had forgotten about.

The other bug, where .NETpad doesn’t correctly identify which theme is selected, remained, however. So I did fix that one myself using the methods I applied earlier to the WinForms version of the app as a guide. As with the WinForms version of .NETpad, the WPF version checks at startup to see which foreground and background colors were saved in settings and then applies those settings to the app. As with the window  state code noted above, this happens in the AppWindow_Initialized() event handler:
...

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