I've made incredible progress on .NETpad's support for session state management and multiple documents and tabs. But the code is brutally difficult, and messy in testing. And it's the type of thing I should only work on with a fresh brain. Foolishly, perhaps, I spent a few hours on it while flying to Mexico on Saturday and did OK, all things considered. But it was late, I was a bit beat up, and I needed a small win.
This is it.
It's nothing earth-shattering, but it's on the to-do list. It's something I had previously changed in one of the several different versions of this project I'm stupidly juggling. And so I didn't really need to write any new code. All I had to do was clone the .NETpad 3.0 for Windows 11 repository in GitHub to a new Visual Studio project to get a clean version of the code base, add my changes to it, and then push the changes back up to GitHub. Then I could check the item off the to-do list and enjoy 10 seconds of peace. Or something.
That item, as noted in the article headline, is a custom MessageBox dialog. It's something I should have done months ago and added to the app in its initial release. I have no idea why I didn't: .NETpad 3.0 includes several nice-looking custom dialogs--for Auto save, Confirmation, Find/replace, and Go to line--and all of them are more complicated than a basic MessageBox. Sometimes you have to just shake your head and not over-think it.
The issue, if you're not familiar, is the system MessageBox you can access with WPF isn't styled for Windows 11.
But the MessageBox dialogs that Notepad displays are properly styled for Windows 11.
Not including the MessageBoxes I use to display error messages, there are two major instances in which .NETpad, like Notepad, needs to display this type of window.
You're using Go to line and try to go to a line that's beyond the end of the document.
You're using Find/replace and the text string you're trying to find doesn't exist in the document.
In both cases, we just need an error message and an OK button. Simple
The MessageBox class
My custom MessageBox is called MessageBoxDialog and it's based on the same basic XAML code I used for the other custom dialogs. This one is as basic as it can be, however, so it's even simpler. It supports a title, a message, and an OK button. The title and message are both TextBlock controls.
There are only three event handlers.
The first one is the constructor, which runs when code elsewhere in the app instantiates a new MessageBoxDialog. It takes two string arguments so that the calling code can send it the desired title and message.
The second is WindowsLoaded(), which runs when the window displays. All this does is give the focus to the OK button. That way, the user can tap Enter or Space to close the window. (They can also press Esc, as I made the OK button the Default button and the Cancel button.)
The third is a Click() event handler for the OK button. The oth...
The post .NETpad 2025: A Custom MessageBox Dialog (Premium) appeared first on Thurrott.com.
Source: View source