The UWP Files: First Steps (Premium)

I spent a lot of time researching UWP and Xamarin Forms over the weekend and decided to renew my efforts to port .NETpad to UWP first.

I spent a lot of time researching the Universal Windows Platform (UWP) and Xamarin Forms over the weekend and decided to renew my efforts to port .NETpad to UWP. And I think I’ll handle this as I did with the WPF port of this Notepad clone: First, I’ll write generally about what I’m doing from time-to-time and then, if there’s a demand for it, I’ll document the process in a series of step-by-step articles.

This doesn’t mean I’m done with the WPF version of .NETpad, or even the WinForms version for that matter. But in the interest of pushing forward quickly, I thought it would be useful to press on with a newer and more modern framework. And while UWP is pretty much the end of the road in a variety of ways, it’s also more modern than WPF and has some interesting advantages.

As you may recall, I made some first steps with a UWP version of .NETpad previously, and I wrote about my earliest experiences back in February. At that time, I noted my struggles with UWP’s support for the Windows 10 dark and light color schemes, and its requirements that I use theme dictionaries to customize how the app looks in both cases. Rafael was a big help with that.

Dark color mode support

Since then, I’ve started over and have moved past what I had previously accomplished. My big concerns for the UWP version are custom dialogs, weird missing bits of functionality, and what I assume will be a long list of things that are harder, for some reason, in UWP.

UWP, like WPF, doesn’t provide a Font dialog or even a Font picker of any kind, but given my experience building one in WPF, I think I’ll be able to make that happen. UWP does apparently provide a Color picker, however, so I will use that in a custom dialog or pane or whatever. And it supports native File Open and Save/Save As dialogs. The app can already open text files, so the basics should all work.

UWP handles user/application settings differently than WinForms and WPF in that there’s no visual designer anymore, so it’s all code-based now. I’m good with that, and it looks straightforward.

There are weird little things. Microsoft added support for traditional menus to UWP a few years ago, and they mostly work fine. But you can’t easily add a checkbox to a menu item, so I need to figure that out so I can correctly check menu items like Format > Word Wrap and View > Status Bar.

Word Wrap enabled. Also word count!

Speaking of which, there’s no status bar control either. But that’s fine, I implemented it using text blocks in a Stack Panel, similarly to how the WPF version of the app works.

<StackPanel Name="StatusBar1" Grid.Row="2" Orientation="Horizontal">
    <TextBlock Name="AutoSaveTextBlock" Text="Auto Save: Off" Padding="10,10,50,10" />
    <TextBlock Name="PositionTextBlock" Text="Ln 1, Col 1" Padding="10,10,50,10" />
    <TextBlock Name="ZoomTextBlock" Text="100%" Padding="10,10,50,10" />
    <TextBlock Name="WordCountTextBlock" Text="0 words" Padding="10,10,50,10" />
</StackPanel>

Keyboard shortcuts are surprisingly easier in UWP than they were in WPF, which is nice: You can implement them inline in the XAML file (for each menu item, for example) and then customize the keyboard shortcut hint in the menu too. So that’s all good.

<MenuFlyoutItem Text=”Open” Name=”OpenMenu” Click=”OpenMenu_Click” KeyboardAcceleratorTextOverride=”Ctrl+O”><MenuFlyoutItem.KeyboardAccelerators><KeyboardAccelerator Modifiers=”Control” Key=”O” /></MenuFlyoutItem.KeyboardAccelerators></MenuFlyoutItem>

So far, I’ve got File > Open, File > Exit, Word Count, Edit > Time/Date, Format > Word Wrap, and View > Status Bar working. It supports light and dark color schemes correctly and dynamically. And there are some niceties built-in to UWP that the app just takes advantage of automatically, like spell-check.

The big next steps are those custom dialogs and the Font/Color picker implementations. We’ll see how well that goes. Then I’ll work on moving the control resources into a separate file—they’re currently clogging up MainPage.xaml—and figuring out UWP’s support for app/user settings. I’m also just using basic Click events for the menu items, but I will be investigating how UPW handles commands and will likely move them all over eventually.

Should keep me busy for a while. 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