WPF Line breaks in string resources
Try the numeric character reference approach:
<sys:String>line1 line2</sys:String>
Note, however, that if you are actually encoding an Inline
you can use:
<LineBreak />
E.g:
<TextBlock>
<TextBlock.Text>
line1 <LineBreak /> line2
</TextBlock.Text>
</TextBlock>
Try to add xml:space="preserve"
to your resource and use
<sys:String x:Key="MyString" xml:space="preserve">line1 line2</sys:String>
If nothing works out, assured solution would be using a converter.
public class NewLineConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var s = string.Empty;
if (value.IsNotNull())
{
s = value.ToString();
if (s.Contains("\\r\\n"))
s = s.Replace("\\r\\n", Environment.NewLine);
if (s.Contains("\\n"))
s = s.Replace("\\n", Environment.NewLine);
if (s.Contains("

"))
s = s.Replace("

", Environment.NewLine);
if (s.Contains("
"))
s = s.Replace("
", Environment.NewLine);
if (s.Contains("
"))
s = s.Replace("
", Environment.NewLine);
if (s.Contains(" "))
s = s.Replace(" ", Environment.NewLine);
if (s.Contains(" "))
s = s.Replace(" ", Environment.NewLine);
if (s.Contains(" "))
s = s.Replace(" ", Environment.NewLine);
if (s.Contains("<br />"))
s = s.Replace("<br />", Environment.NewLine);
if (s.Contains("<LineBreak />"))
s = s.Replace("<LineBreak />", Environment.NewLine);
}
return s;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Working solution: shift+enter in the dictionary resource window in visual studio seems to work.