优化 MarkdownWpfRenderer.cs 中的表格处理逻辑
- 将未使用的循环变量名改为 `_`。 - 使用 `var` 简化 `colIndex` 的类型声明。 - 根据列的对齐方式设置单元格内容的水平对齐。 - 微调代码格式和注释,提高可读性。
This commit is contained in:
parent
5aabcbdda6
commit
cf3bd8a294
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue