From cf3bd8a2945b39378d7bb2f930be8e318b67da6e Mon Sep 17 00:00:00 2001 From: lihanbo Date: Mon, 3 Mar 2025 09:23:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20MarkdownWpfRenderer.cs=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=A1=A8=E6=A0=BC=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将未使用的循环变量名改为 `_`。 - 使用 `var` 简化 `colIndex` 的类型声明。 - 根据列的对齐方式设置单元格内容的水平对齐。 - 微调代码格式和注释,提高可读性。 --- .../Markdown/MarkdownWpfRenderer.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/EleCho.MdViewer/src/EleCho.MdViewer/Markdown/MarkdownWpfRenderer.cs b/src/EleCho.MdViewer/src/EleCho.MdViewer/Markdown/MarkdownWpfRenderer.cs index 17dd35f..56d8b8a 100644 --- a/src/EleCho.MdViewer/src/EleCho.MdViewer/Markdown/MarkdownWpfRenderer.cs +++ b/src/EleCho.MdViewer/src/EleCho.MdViewer/Markdown/MarkdownWpfRenderer.cs @@ -192,7 +192,7 @@ public class MarkdownWpfRenderer tableElement .BindTableBackground(); - foreach (var col in table.ColumnDefinitions) + foreach (var _ in table.ColumnDefinitions) { if (cancellationToken.IsCancellationRequested) return new FrameworkElement(); @@ -200,7 +200,7 @@ public class MarkdownWpfRenderer tableContentElement.ColumnDefinitions.Add( new ColumnDefinition() { - Width = GridLength.Auto + Width = GridLength.Auto, }); } @@ -219,12 +219,12 @@ public class MarkdownWpfRenderer Height = GridLength.Auto }); - int colIndex = 0; + var colIndex = 0; foreach (var colBlock in row) { if (colBlock is not TableCell cell) continue; - + var col = table.ColumnDefinitions[colIndex]; Border cellElement = new Border() { Padding = new Thickness(NormalSize / 2, NormalSize / 4, NormalSize / 2, NormalSize / 4) @@ -236,7 +236,7 @@ public class MarkdownWpfRenderer cellElement.Child = cellContentElement; cellElement .BindTableBorder(); - + //block. cellContentElement.Margin = new Thickness(4); if (rowIndex % 2 == 1) @@ -244,6 +244,19 @@ public class MarkdownWpfRenderer Grid.SetRow(cellElement, rowIndex); Grid.SetColumn(cellElement, colIndex); + if (col.Alignment == TableColumnAlign.Left) + { + cellContentElement.HorizontalAlignment = HorizontalAlignment.Left; + } + else if (col.Alignment == TableColumnAlign.Center) + { + cellContentElement.HorizontalAlignment = HorizontalAlignment.Center; + } + else if (col.Alignment == TableColumnAlign.Right) + { + cellContentElement.HorizontalAlignment = HorizontalAlignment.Right; + } + tableContentElement.Children.Add(cellElement);