界面控件DevExpress WPF v24.2新版亮点:富文本编辑器功能升级

翻译|产品更新|编辑:龚雪|2025-06-16 11:35:17.623|阅读 3 次

概述:DevExpress WPF控件近期全新发布v24.2,此版本进一步升级了富文本编辑器的功能,欢迎下载最新版体验!

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

DevExpress WPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。

DevExpress WPF控件近期全新发布v24.2,此版本进一步升级了富文本编辑器的功能,欢迎下载最新版体验!

DevExpress技术交流群11:749942875      欢迎一起进群讨论

富文本编辑器
大小写格式

DevExpress WPF富文本编辑器支持大小写字符格式,使用小写字母格式的Word文档可以预览、打印和导出为PDF。要在代码中启用格式化,请使用CharacterProperties.SmallCaps属性:

C#

Document document = richEditControl.Document;
Paragraph paragraph = document.Paragraphs[0];
CharacterProperties characterProperties = document.BeginUpdateCharacters(paragraph.Range);
characterProperties.SmallCaps = true;
document.EndUpdateCharacters(characterProperties);

此外新版本在Font复选框中添加了一个Small Caps(大小写)复选框,以便通过UI应用格式。

页面边框

DevExpress WPF富文本编辑器现在支持页面边框,具有页面边框的Word文档可以保存而不会丢失内容,可以预览、打印和导出为PDF。

DevExpress WPF v24.2产品图集

v24.2还实现了用于在代码管理页面边框的API,可以为每个文档部分单独设置边框,使用SectionPageBorders属性来访问和修改特定部分的边框。使用新的API,您可以修改以下边框设置:

  • 线条样式
  • 颜色
  • 宽度
  • 距文本或页边的距离

您还可以对部分中的特定页面应用边框:对所有页面、仅对第一个页面或除第一个页面外的所有页面应用边框,可以更改边框的z轴顺序以显示它们在主文本的前面或后面。下面的代码片段在包含两个部分的文档中应用不同的边框:

C#

Document document = richEditControl.Document;
string pageBreaks = "\f\f\f";
// Generate a document with two sections and multiple pages in each section
document.AppendText(pageBreaks);
document.Paragraphs.Append();
document.AppendSection();
document.AppendText(pageBreaks);

// Set borders for the first page of the first section
SetPageBorders(pageBorders1.LeftBorder, BorderLineStyle.Single, 1f, Color.Red);
SetPageBorders(pageBorders1.TopBorder, BorderLineStyle.Single, 1f, Color.Red);
SetPageBorders(pageBorders1.RightBorder, BorderLineStyle.Single, 1f, Color.Red);
SetPageBorders(pageBorders1.BottomBorder, BorderLineStyle.Single, 1f, Color.Red);
pageBorders1.AppliesTo = PageBorderAppliesTo.FirstPage;

Section secondSection = document.Sections[1];
SectionPageBorders pageBorders2 = secondSection.PageBorders;

// Set borders for all pages of the second section
SetPageBorders(pageBorders2.LeftBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetPageBorders(pageBorders2.TopBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetPageBorders(pageBorders2.RightBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetPageBorders(pageBorders2.BottomBorder, BorderLineStyle.Double, 1.5f, Color.Green);
pageBorders2.AppliesTo = PageBorderAppliesTo.AllPages;
pageBorders2.ZOrder = PageBorderZOrder.Back;

//.....
void SetPageBorders(PageBorder border, BorderLineStyle lineStyle,
float borderWidth, Color color) {
border.LineStyle = lineStyle;
border.LineWidth = borderWidth;
border.LineColor = color;
}
段落边框API

v24.2在代码中实现了新的API来管理Word文档的段落边界,使用这些新API,您可以为文档段落添加边框,单独更改每种边框类型(上、左、右、下或水平)的边框样式、颜色和厚度,或者删除边框格式。此外,还可以管理段落样式的段落边框设置和编号列表中的列表级别。

DevExpress WPF v24.2产品图集

段落的边框设置可以通过ParagraphBorders类来实现,使用Paragraph.Borders, ParagraphProperties.Borders或ParagraphStyle.Borders属性来获取段落边界对象,并根据您的具体使用场景修改边框设置。

C#

richEditControl.Text = "paragraph 1\r\nparagraph 2\r\nparagraph 3\r\nparagraph 4\r\n";
Document document = richEditControl.Document;

// Setup borders for one paragraph
Paragraph firstParagraph = document.Paragraphs[0];
ParagraphBorders borders1 = firstParagraph.Borders;
SetBorders(borders1.LeftBorder, BorderLineStyle.Single, 1f, Color.Red);
SetBorders(borders1.TopBorder, BorderLineStyle.Single, 1f, Color.Red);
SetBorders(borders1.RightBorder, BorderLineStyle.Single, 1f, Color.Red);
SetBorders(borders1.BottomBorder, BorderLineStyle.Single, 1f, Color.Red);

// Setup borders for multiple paragraphs
Paragraph secondParagraph = document.Paragraphs[1];
Paragraph forthParagraph = document.Paragraphs[3];
DocumentRange paragraphRange = document.CreateRange(secondParagraph.Range.Start,
forthParagraph.Range.End.ToInt() - secondParagraph.Range.Start.ToInt());
ParagraphProperties paragraphProperties = document.BeginUpdateParagraphs(paragraphRange);
ParagraphBorders borders2 = paragraphProperties.Borders;
SetBorders(borders2.LeftBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetBorders(borders2.TopBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetBorders(borders2.RightBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetBorders(borders2.BottomBorder, BorderLineStyle.Double, 1.5f, Color.Green);
SetBorders(borders2.HorizontalBorder, BorderLineStyle.Double, 1.5f, Color.Green);
document.EndUpdateParagraphs(paragraphProperties);

// Reset paragraph borders
secondParagraph.Borders.Reset();

//...
void SetBorders(ParagraphBorder border, BorderLineStyle lineStyle,
float borderWidth, Color color) {
border.LineStyle = lineStyle;
border.LineWidth = borderWidth;
border.LineColor = color;
}
表格的Alt文本

Table.Title和Table.Description属性允许您指定Word文档表中包含的信息替代的、基于文本的表示形式。在将Word文档导出为可访问的PDF格式时,也会使用表标题和描述。

C#

RichEditDocumentServer documentProcessor = new RichEditDocumentServer();
documentProcessor.LoadDocument("tables.docx");
Document document = documentProcessor.Document;
if(document.Tables.Count > 0) {
Table table = document.Tables[0];
table.Title = "Table title..";
table.Description = "Table description..";
}

注意,表标题和描述只支持OpenXml文档格式(.docx, .docm, .dotx, .dotm) 和HTML。

AI驱动的Alt文本对话框图像

v24.2附带了一个新的AI支持的Alt Text对话框,该对话框允许您为Word文档中的形状对象设置可访问的描述,或将非信息文档图形标记为装饰性(此设置允许屏幕阅读器在扫描文档时忽略装饰性图形)。此外,您可以使用Alt Text对话框来使用AI的力量为文档图像生成有意义的描述。

DevExpress WPF v24.2产品图集

要启用此功能,请注册AI服务,然后在WPF应用程序中附加GenerateImageDescriptionBehavior操作。

如果没有为DevExpress WPF富文本编辑器注册GenerateDescriptionBehavior,则Generate按钮将被禁用,只能为文档图像生成描述。当选择形状或图表对象时,Generate选项将被禁用。

新的内置对话框可以从形状的上下文菜单中获得,要激活Alt Text对话框,请选择文档形状、图像或图表,打开上下文菜单并单击"View Alt Text..."上下文菜单项。

Macros API

Document.VbaProject属性允许您以编程方式访问存储在启用宏的Word文件中的VBA项目,使用VbaProject.Modules集合来获取有关VBA项目模块的信息(模块的数量、模块的名称和二进制数据),或者从项目中删除特定的模块。如果当前文档格式不支持宏,或者启用宏的文档不包含宏,VbaProject.Modules集合为空。

C#

// Check if the current document has macros and remove them
Document document = wordProcessor.Document;
if(document.VbaProject.Modules.Count > 0)
document.VbaProject.Modules.Clear();

更多产品资讯及授权,欢迎来电咨询:023-68661681


更多DevExpress线上公开课、中文教程资讯请上中文网获取

关于慧都科技

慧都是⼀家⾏业数字化解决⽅案公司,专注于软件、⽯油与⼯业领域,以深⼊的业务理解和⾏业经验,帮助企业实现智能化转型与持续竞争优势。

慧都是DevExpress的中国区的合作伙伴,DevExpress作为用户界面领域的优秀产品,帮助企业高效构建权限管理、数据可视化(如网格/图表/仪表盘)、跨平台系统(WinForms/ASP.NET/.NET MAUI)及行业定制解决方案,加速开发并强化交互体验。


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:慧都网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP