0

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...

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • I just tried it, and new lines are stored without any issue. I tried this: `ApplicationData.Current.RoamingSettings.Values["foo"] = "Hello\nWorld!";` You can debug your stored values following this page: http://lunarfrog.com/blog/2012/09/13/inspect-app-settings/ – kiewic Dec 18 '13 at 07:36
  • Try from a TextBox against Windows 8.1. I'm not making this up! – Alexandru Dec 18 '13 at 13:46

1 Answers1

0

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.

yasouser
  • 5,113
  • 2
  • 27
  • 41
  • "The name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size. The sync engine may limit the total size of settings and files that can roam." - But even if you're under 255 and have a \n, it doesn't let you save it. – Alexandru Dec 18 '13 at 12:56