我是 wpf 的新手,我想在 wpf 文本块中的一行中显示文本。
例如。:
<TextBlock
Text ="asfasfasfa
asdasdasd"
</TextBlock>
TextBlock默认以两行显示,
但我希望它只在一行中,像这样“asafsf asfafaf”。我的意思是在一行中显示所有文本,即使文本中有不止一行
我应该怎么办?
使用转换器:
<TextBlock Text={Binding Path=TextPropertyName,
Converter={StaticResource SingleLineTextConverter}}
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();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)