How do you save a string containing a newline character under the RoamingSettings in Windows Store Apps?

357 views Asked by At

I've noticed that this...

void MyTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    ApplicationData.Current.RoamingSettings.Values["Text"] = Text;
}

...is unreliable in Windows 8.1 Store Apps when the Text of your TextBox contains a newline character (AKA it doesn't save when you have a newline \n in the Text object). What are the ways around this?

Using Regex.Escape(Text) and Regex.Unescape((string)ApplicationData.Current.RoamingSettings.Values["Text"]) doesn't seem to work for me, either. The sandbox probably tries to circumvent any \'s to block shellcode injection into the OS layer.

The only thing that seems to work is to save to file in the RoamingSettings...

1

There are 1 answers

1
yasouser On

Look at the example code in here: ApplicationData.RoamingSettings | roamingSettings property

With regards to this:

Windows 8.1 Store Apps when the Text of your TextBox contains a newline character (AKA it doesn't save when you have a newline \n in the Text object). What are the ways around this?

Try by setting both the TextBox.AcceptsReturn property and TextBox.Multiline property to true. See the sample in TextBox.AcceptsReturn link above.