How to display the text in one line in wpf textblock

后端 未结 2 1716
情歌与酒
情歌与酒 2021-01-12 07:47

I\'m a newbie with wpf , what i want to display the text in one line in wpf textblock. eg.:

         


        
2条回答
  •  一生所求
    2021-01-12 07:53

    Use a Converter:

        

    SingleLineTextConverter.cs:

    public class SingleLineTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string s = (string)value;
            s = s.Replace(Environment.NewLine, " ");
            return s;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

提交回复
热议问题