首页 > Windows开发 > 详细

WPF 字符串溢出判断,字符串长度是否超过控件宽度

时间:2018-04-04 13:58:20      阅读:305      评论:0      收藏:0      [点我收藏+]

TextBloc可以将TextTrimming属性设置为CharacterEllipsis

 

其他控件可以在控件大小变更或者其他事件上附加下列方法

 1         private void OnEllipsis(object sender, SizeChangedEventArgs e)
 2         {
 3             FormattedText formattedText = new FormattedText(
 4                 this.Header.ToString(),
 5                 Thread.CurrentThread.CurrentCulture,
 6                 this.FlowDirection,
 7                 new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch),
 8                 this.FontSize,
 9                 this.Foreground);
10 
11             this.IsEllipsis = formattedText.Width > e.NewSize.Width;
12         }

 

WPF 字符串溢出判断,字符串长度是否超过控件宽度

原文:https://www.cnblogs.com/RabbitCC/p/8716659.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!