博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF TextBlock IsTextTrimmed 判断文本是否超出
阅读量:4482 次
发布时间:2019-06-08

本文共 1054 字,大约阅读时间需要 3 分钟。

原文:

WPF TextBlock 设置TextTrimming情况下

判断 isTextTrimmed(Text 文本是否超出 是否出现了省略号)

    private bool IsTextTrimmed(TextBlock textBlock)        {            Typeface typeface = new Typeface(                textBlock.FontFamily,                textBlock.FontStyle,                textBlock.FontWeight,                textBlock.FontStretch);            FormattedText formattedText = new FormattedText(                textBlock.Text,                System.Threading.Thread.CurrentThread.CurrentCulture,                textBlock.FlowDirection,                typeface,                textBlock.FontSize,                textBlock.Foreground);            formattedText.MaxTextWidth = textBlock.ActualWidth;            bool isTrimmed = formattedText.Height > textBlock.ActualHeight ||                             formattedText.Width >textBlock.MaxTextWidth;        return isTrimmed;      }

:绘制文本,也可以根据当前控件样式(最大高宽/字体样式),获取当前控件的最大容纳字符数。

根据以上属性,可以做很多事,如文本超出时,设置ToolTip、文本替换等。

posted on
2018-05-21 14:24 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lonelyxmas/p/9067031.html

你可能感兴趣的文章
dataGridview显示行时多显示一行??如何去除
查看>>
Web 前端开发精华文章推荐(jQuery、HTML5、CSS3)【系列十二】
查看>>
第一天关于PS的学习
查看>>
[心跳] 互联网的长在线、心跳和断线重连
查看>>
手机端触屏滚动效果
查看>>
团队作业Week3
查看>>
mysql导入导出命令
查看>>
JDK、 反射
查看>>
评论《最为寂寞是上海》
查看>>
Delphi使用Python来解码邮件
查看>>
display:none 与 opacity:0
查看>>
路由传参数
查看>>
通过Roslyn构建自己的C#脚本 资料记录
查看>>
mysql优化
查看>>
MySQL(一)
查看>>
hibernate笔记--实体类映射文件"*.hbm.xml"详解
查看>>
自动分区、格式化、挂载脚本
查看>>
Hive表文件格式ORC导数
查看>>
malloc_stats---检查内存泄露的神器
查看>>
python之路-day02
查看>>