The UWP Notepad Project (Redux): More Settings (Premium)

In this installment of the UWP Notepad project, we’ll implement the non-font user settings and a workaround for a UWP weirdism that had me stumped for days.
FUBAR
UWP did it to me again. Despite the fact that I’d previously created four different versions of this app and thought I had figured out how to correctly read and save user settings, it wasn’t working correctly in this version. And after spending several hours over two days trying to figure out the problem, I finally figured out a workaround.

I can’t claim that actual tears were involved, but this incident is a great example of why UWP is so f&$%ing broken if you’re used to WPF, and why I spent so much of the past 48 hours alternating between rage and a funk state. I hate this. I hate the illogical nature of it.

The issue, in short, is that UWP quietly triggers certain event handlers unexpectedly at app launch, and that in doing so it short-circuited my attempts at accurately reading user settings and then configuring the app accordingly. Perhaps not coincidentally, this behavior seems to be tied to the weeks-long issues I had had figuring out the asynchronous programming techniques required for both file access and displaying pop-up windows in UWP. We’ll get to that in a future installment. For now, I’d like to just move past this horrific problem and make some progress.

And while I can’t explain this, and honestly couldn’t care less at this point why it even happens, the font (family) and font size settings we create, edit, and save in this app work just fine, but the other settings---which include the fold bold and font italic properties, plus Word Wrap, Status Bar, Display (Command Bar) Labels, and Auto Save---do/did not. So we need to make some changes to the code I provided in the previous installment. And then implement the workaround to what, to me, seems like bizarre behavior.
Ch-ch-changes
First, we’re going to change the MyFontBold and MyFontItalic user settings from string values to Boolean values. Before making that change, however, we should reset the app’s user settings, which can do by running the app and choosing “…” (See more) > Reset Settings. Good thing we added that.

Next, open MainPage.xaml.cs and locate the ReadSettings() method. Then, change the Font Bold and Font Italic if-then blocks to work with Boolean values like so:
// Font Bold
if (myFontBold == true)
    TextBox1.FontWeight = FontWeights.Bold;
else
    TextBox1.FontWeight = FontWeights.Normal;

// Font Italic
if (myFontItalic == true)
    TextBox1.FontStyle = FontStyle.Italic;
else
    TextBox1.FontStyle = FontStyle.Normal;
Note that the myFontBold and myFontItalic references will trigger errors. No worries: We’re going to add the appropriate variable declarations soon.

Next, find the SaveFontSettings() method. Here, we need to make similar changes so that this method saves FontBold and FontItalic as Boolean values, not s...

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