翻譯|產品更新|編輯:龔雪|2025-06-16 11:35:17.623|閱讀 83 次
概述: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。
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; }
v24.2在代碼中實現了新的API來管理Word文檔的段落邊界,使用這些新API,您可以為文檔段落添加邊框,單獨更改每種邊框類型(上、左、右、下或水平)的邊框樣式、顏色和厚度,或者刪除邊框格式。此外,還可以管理段落樣式的段落邊框設置和編號列表中的列表級別。
段落的邊框設置可以通過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; }
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。
v24.2附帶了一個新的AI支持的Alt Text對話框,該對話框允許您為Word文檔中的形狀對象設置可訪問的描述,或將非信息文檔圖形標記為裝飾性(此設置允許屏幕閱讀器在掃描文檔時忽略裝飾性圖形)。此外,您可以使用Alt Text對話框來使用AI的力量為文檔圖像生成有意義的描述。
要啟用此功能,請注冊AI服務,然后在WPF應用程序中附加操作。
如果沒有為DevExpress WPF富文本編輯器注冊GenerateDescriptionBehavior,則Generate按鈕將被禁用,只能為文檔圖像生成描述。當選擇形狀或圖表對象時,Generate選項將被禁用。
新的內置對話框可以從形狀的上下文菜單中獲得,要激活Alt Text對話框,請選擇文檔形狀、圖像或圖表,打開上下文菜單并單擊"View Alt Text..."上下文菜單項。
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作為用戶界面領域的優秀產品,幫助企業高效構建權限管理、數據可視化(如網格/圖表/儀表盤)、跨平臺系統(WinForms/ASP.NET/.NET MAUI)及行業定制解決方案,加速開發并強化交互體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網