views:

46

answers:

1

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 "&lt ; LineBreak/ &gt ;" (w/o space),

tried /r/n

tried &#13;&#10;

None of the options worked, anyone got ideas?

+4  A: 

\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&#10;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&#10;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.

Chris Taylor
did both way directly into xaml under text property
C_Rance
Confirmed not working. just did a test directly in my resource file
C_Rance
i put \r\nsss/r/nsdss, it show me exactly what I have keyed in
C_Rance
@C_Rance: See my update which I tested with SL4
Chris Taylor
Yup, worked in both scenario, but if u use for example text="{StaticResource message}". In the app.xaml,<system:String x:Key="message">HelloWorld or Hello\nWorld </system:String>. \n will be shown literally, won't show though, and shows as if it is a empty space
C_Rance
@C_Rance: Maybe using a converter is the way forward for this solution.
Ardman
@Ardman, thanks, browse through it, lazy to test it now as its midnight over at my side. So I presume for this case I will be using \r\n method as it is C#. But I still hope that can do something like what I intended. This will be my workaround if really still cant think of anything
C_Rance
@C_Rance, this works for resources as well, you need to specify space="preserve" see my edit.
Chris Taylor
I tested and it works for me, when set directly in the Xaml, but \n does not do it unless it is used in the code behind, which is exactly what @Chris Taylor says. This is actually a problem I was having, too, and did not want to use <Linebreak/>. Slick!
Cyberherbalist
@Chris, woah, thanks man. anyway space="preserve" is totally xml right? mind telling me what are these type of keywords called?
C_Rance
@C_Rance: See the XML Specification section 2.10 White Space Handling, this is standard XML. http://www.w3.org/TR/REC-xml/
Chris Taylor
@Chris, once again thanks. actually I tot there were more xml: type of keywords that I do not know of.
C_Rance