WPF Textblock, linebreak in Text attribute

后端 未结 15 1217
南方客
南方客 2021-02-03 16:37

Is there a way to have \\n make a line break in a TextBlock?


Or is there a

15条回答
  •  梦如初夏
    2021-02-03 17:13

    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();
        }
    }
    

提交回复
热议问题