In the previous installment, we created a custom Content dialog because WPF doesn't support the native control in Windows. And then we built out our first dialog, Save confirmation, using that as a base. This time, we'll use it to create more dialogs. This includes the Go to line dialog and the Auto save dialog(s)--there are actually two of them--and maybe an unexpected new entry too.
Part of the difficulty for me here is that I've created several different new versions of .NETpad this past summer as I've worked to update it to support Windows 11 theming and other modern features thanks to a big update to WPF, now in preview. Each of these .NETpad versions has some unique advances, and as I write this how-to series documenting how one might modernize a legacy WPF app like this, I've encountered some interesting new issues. And one of those came to light last night as I was taking screenshots for this article. So we'll see where this takes us.
For now, we have what I think is a solid base for future custom dialogs that look and feel correct in Windows 11. Well, mostly: The WPF update that enables this work isn't fully baked, so there are still some style issues, including one that impacts this work when you mouse over the accent-colored default button in a dialog, and it doesn't handle the temporary color change correctly. But that's on Microsoft, and it's not a big deal. If and when it's fixed, the app should just look and work as expected without requiring much in the way of code changes. He writes, naively.
In addition to creating our custom Content dialog in the previous article, we also implemented the first, and arguably the most important, of the resulting custom dialogs, what I call the Save confirmation dialog. That was a lot of work, but creating the next two/three--Go to line and the two Auto save dialogs--should be relatively straightforward, as they follow the same model.
Implement the Go to line dialog
Go to line is an outlier among our custom Content dialogs in that it's the only one to use the optional text box. As a reminder, this is what it looks like in Notepad.
To get started with our version of this, we'll use a temporary top-level menu item to launch our new Go to line dialog while we create it, and then we'll move it into the main code base. So locate the temporary menu items in MainWindow.xaml--their headers are " "Template Test" and "Save confirmation," respectively--delete the first one, and change the header of the remaining item (formerly "Save confirmation") to "Go to line." We could change the name of the OnClick() event handler to match, but this is temporary, so I didn't bother myself.
Now, we can edit the code in the (unfortunately named) SaveConfirmationMenuItem_Click() event handler in MainWindow.xaml.cs so that it makes sense for the Go to line dialog. This includes a few quick edits to the name of the ContentDialog instance we're creating and to the "Create" method it will...
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.