Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF and string formatting

Suppose I have some XAML like this:

<Window.Resources>
  <v:MyClass x:Key="whatever" Text="foo\nbar" />
</Window.Resources>

Obviously I want a newline character in the MyClass.Text property, but the XAML parser constructs the object with the literal string "foo\nbar".

Is there (a) a way to convince the parser to translate escape sequences, or (b) a .NET method to interpret a string in the way that the C# compiler would?

I realize that I can go in there looking for \n sequences, but it would be nicer to have a generic way to do this.

like image 629
chrisd Avatar asked Dec 07 '22 09:12

chrisd


1 Answers

You can use XML character escaping

<TextBlock Text="Hello&#13;World!"/>
like image 69
Vriff Polo Avatar answered Dec 09 '22 22:12

Vriff Polo