WPF Paragraph获取或修改文本内容
发布日期:2021-08-15 22:29:38 浏览次数:31 分类:技术文章

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

一、说明

Paragraph继承自Block,Block继承自TextElement,在TextElement中

//        // 摘要:        //     获取表示元素中内容末尾的 System.Windows.Documents.TextPointer。        //        // 返回结果:        //     表示 System.Windows.Documents.TextElement 中内容末尾的 System.Windows.Documents.TextPointer。        public TextPointer ContentEnd { get; }        //        // 摘要:        //     获取表示元素中内容开头的 System.Windows.Documents.TextPointer。        //        // 返回结果:        //     表示 System.Windows.Documents.TextElement 中内容开头的 System.Windows.Documents.TextPointerContext。        public TextPointer ContentStart { get; }

通过获取ContentStart点和ContentEnd点之间的内容,获取段落内容:TextRand.Text

//    // 摘要:    //     表示两个 System.Windows.Documents.TextPointer 位置之间的所选内容。    public class TextRange : ITextRange    {        // 参数:        //   position1:        //     标记用于组成新 System.Windows.Documents.TextRange 的所选内容的一端的固定定位点位置。        //        //   position2:        //     标记用于组成新 System.Windows.Documents.TextRange 的所选内容的另一端的可移动位置。        public TextRange(TextPointer position1, TextPointer position2);

实例代码:

//获取段落部分的内容Paragraph p = doc.FindName("one") as Paragraph;TextRange range = new TextRange(p.ContentStart, p.ContentEnd);string str = range.Text;MessageBox.Show(str);//修改段落内容p.Inlines.Clear();p.Inlines.Add(new Run("天涯共此时"));

 

转载于:https://www.cnblogs.com/tianma3798/p/5929233.html

转载地址:https://blog.csdn.net/weixin_30781107/article/details/97139624 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php缓存与加速分析与汇总
下一篇:GPRS模块SIM300的使用

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月01日 01时23分45秒