如何在wpf文本块中显示一行中的文本 [英] How to display the text in one line in wpf textblock
本文介绍了如何在wpf文本块中显示一行中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 wpf 的新手,我想在 wpf 文本块中的一行中显示文本.例如:
I'm a newbie with wpf , what i want to display the text in one line in wpf textblock. eg.:
<TextBlock
Text ="asfasfasfa
asdasdasd"
</TextBlock>
TextBlock 默认分两行显示,
TextBlock display it in two lines default,
但我只想要像这样asafsf asfafaf"这样的一行.我的意思是在一行中显示所有文本,即使文本中有不止一行
我该怎么办?
but i want it in only one line like this"asafsf asfafaf". I mean show all the text in one line even there are more than one lines in the text
what should i do?
推荐答案
使用转换器:
<TextBlock Text={Binding Path=TextPropertyName,
Converter={StaticResource SingleLineTextConverter}}
SingleLineTextConverter.cs:
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();
}
}
这篇关于如何在wpf文本块中显示一行中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文