I know that some will reply things such as <LineBreak/>
this is not what I'm looking for.
I want to know if 开发者_如何转开发I store textblock's string in a resource file, can I do some thing about it to make the text in textblock to go to a new line.
tried "< ; LineBreak/ > ;"
(w/o space),
tried /r/n
tried
None of the options worked, anyone got ideas?
\r\n
should do the trick, I think you had the slashes the wrong way around. Even just \n
should work.
In XAML the following works
<TextBlock x:Name="txtMyText" Text="Hello World"/>
While in the code behind this works
txtMyText.Text = "Hello\nWorld";
For resources, you need to specify xml:space="preserve"
<system:String x:Key="message" xml:space="preserve">Hello World</system:String>
Using space preserve you can also do the following
<system:String x:Key="message" xml:space="preserve">Hello
World</system:String>
Note, there are no extra spaces because they would show up in the TextBlock
because now all white space characters become significant.
Just tried with SL5:
Open Resx file Add a new string. Give it a name (Name column) Enter any value you want (Value column). If you need a linebreak just press SHIFT+ENTER.
In code behind, MyTextBlock.Text=MyResource.MyItem;
Your textblock will correctly show your linebreaks.
精彩评论