.NETpad 2025: Tabs First Steps (Premium)

I've been pushing ahead on some of the more complex coding that .NETpad will require for tabs and state management. But in working through that mess, it occurred to me to take a step back, follow my own advice, and focus on one of the more fundamental aspects of this app update.

I am referring, of course, to tabs.

That sounds fairly obvious, I know. But tabs are complex, and it's still not clear to me that the WPF implementation of this feature--via its TabControl and TabItem controls--is up to the task. So let me step through what I'd like to do, and what I've already completed, and a few unknowns (to me).

In WPF, the TabControl is a container for individual TabItems. That's pretty straightforward, and similar in many ways to how a Menu control and the MenuItems it contains work. Tabs are also well-understood from a usage perspective, as we've been using tabs in web browsers for what feels like forever. And Microsoft, of course, has been adding tabs to individual in-box Windows apps--so far, File Explorer, Notepad, Terminal--since the release of Windows 11.

But tabs are complex to code with WPF. And for so many reasons.

I've mentioned the style issues a few times. But regardless of the new and buggy Windows 11 theming issues in WPF, this framework's implementation of tabs hasn't visually mapped to how tabs display in Windows for several years or more. And fixing that--or working around it--is difficult. I came up with an OK solution for now, but I would like to improve this, so that .NETpad looks more natural, and more like Notepad.

Basic functionality is another issue. When WPF appeared, Microsoft mostly used tabs in control panel windows like System Properties as a way to display multiple pages of settings in a single window that could fit in the low resolution displays of the day. These interfaces were static, laid out at design time, and not dynamic.

But the tabs in Notepad and other apps are dynamic, The user can open an arbitrary number of tabs and then close them, randomly, as they see fit. Tabs-based apps need to accommodate this behavior and scale the UI accordingly. The tabs resize as needed, such as when the user adds or closes them, or when the app window is resized. To my knowledge, WPF tabs do not support this functionality natively, so I need to figure that out. (If you know differently, I'm listening.)

As I wrote previously, supporting multiple documents is complex. Previously, .NETpad supported a single document (per app instance), so tracking document state--via variables like DocumentIsSaved, TextHasChanged, and so on--was relatively easy. But now there will be an arbitrary, ever-changing number of documents, each in its own tab and with its own document state. That's a lot of data to track.

But there's more. Notepad also supports a feature I call session state, which is enabled by default, by which the app remembers which documents--some of which could be saved to disk and some not--were...

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