forked from CommunityToolkit/Labs-Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTable.cs
57 lines (47 loc) · 1.62 KB
/
MyTable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using CommunityToolkit.WinUI.Controls.MarkdownTextBlockRns;
using Markdig.Extensions.Tables;
namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
internal class MyTable : IAddChild
{
private Table _table;
private Paragraph _paragraph;
private MyTableUIElement _tableElement;
public TextElement TextElement
{
get => _paragraph;
}
public MyTable(Table table, MarkdownThemes themes)
{
_table = table;
_paragraph = new Paragraph();
var row = table.FirstOrDefault() as TableRow;
var column = row == null ? 0 : row.Count;
_tableElement = new MyTableUIElement
(
column,
table.Count,
borderThickness: 1,
themes.BorderBrush,
themes.TableHeadingBackground,
themes.CornerRadius
);
var inlineUIContainer = new InlineUIContainer();
inlineUIContainer.Child = _tableElement;
_paragraph.Inlines.Add(inlineUIContainer);
}
public void AddChild(IAddChild child)
{
if (child is MyTableCell cellChild)
{
var cell = cellChild.Container;
Grid.SetColumn(cell, cellChild.ColumnIndex);
Grid.SetRow(cell, cellChild.RowIndex);
Grid.SetColumnSpan(cell, cellChild.ColumnSpan);
Grid.SetRowSpan(cell, cellChild.RowSpan);
_tableElement.Children.Add(cell);
}
}
}