Is there a way to have \\n
make a line break in a TextBlock
?
Or is there a
just use the AccessText control. you can use it like a label and you have the property TextWrapping="WrapWithOverflow"
eg.
Mine is like that and it's working fine. Also, you don't have any problems on changing the text dinamically.
this 

did not work for me, when I used binding. But this works:
$"first line {Environment.NewLine} second line"
<LineBreak/> will not work if it is inside a collection such as Grid or StackPanel. In such cases the following would work as shown:
I know this is ressurecting an old question, but I had the same problem. The solution for me was to use HTML encoded line feeds (&#10;
).
Line1&#10;Line2
Looks like
Line1
Line2
For more of the HTML encoded characters check out w3schools
The Best way that worked for me for multiple lines in the same Textblock is:
<TextBlock>
text1
<LineBreak/>
text2
</TextBlock>
Make sure to not use TextWrapping="Wrap". Use TextWrapping="NoWrap" or use nothing.
I'm late to the party but .. this is more or less how I did it ,(mind my ItemSources are plain strings, not formatted , and I didn't need to 'convertBack' anything)
public class SpaceToLineBreakConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (!String.IsNullOrEmpty(value as string))
? new Regex(@"\s").Replace(value as string, "\n")
: value;
}
public object ConvertBack(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}