5
5
using CommunityToolkit . Labs . WinUI . MarkdownTextBlock . Renderers ;
6
6
using CommunityToolkit . Labs . WinUI . MarkdownTextBlock . TextElements ;
7
7
using Markdig ;
8
+ using Markdig . Syntax ;
8
9
9
10
namespace CommunityToolkit . Labs . WinUI . MarkdownTextBlock ;
10
11
@@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control
30
31
typeof ( MarkdownTextBlock ) ,
31
32
new PropertyMetadata ( null , OnTextChanged ) ) ;
32
33
34
+ private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty . Register (
35
+ nameof ( MarkdownDocument ) ,
36
+ typeof ( MarkdownDocument ) ,
37
+ typeof ( MarkdownTextBlock ) ,
38
+ new PropertyMetadata ( null ) ) ;
39
+
33
40
public MarkdownConfig Config
34
41
{
35
42
get => ( MarkdownConfig ) GetValue ( ConfigProperty ) ;
@@ -42,6 +49,12 @@ public string Text
42
49
set => SetValue ( TextProperty , value ) ;
43
50
}
44
51
52
+ public MarkdownDocument ? MarkdownDocument
53
+ {
54
+ get => ( MarkdownDocument ) GetValue ( MarkdownDocumentProperty ) ;
55
+ private set => SetValue ( MarkdownDocumentProperty , value ) ;
56
+ }
57
+
45
58
public event EventHandler < LinkClickedEventArgs > ? OnLinkClicked ;
46
59
47
60
internal void RaiseLinkClickedEvent ( Uri uri ) => OnLinkClicked ? . Invoke ( this , new LinkClickedEventArgs ( uri ) ) ;
@@ -102,8 +115,8 @@ private void ApplyText(bool rerender)
102
115
103
116
if ( ! string . IsNullOrEmpty ( Text ) )
104
117
{
105
- var markdown = Markdown . Parse ( Text , _pipeline ) ;
106
- _renderer . Render ( markdown ) ;
118
+ this . MarkdownDocument = Markdown . Parse ( Text , _pipeline ) ;
119
+ _renderer . Render ( this . MarkdownDocument ) ;
107
120
}
108
121
}
109
122
}
0 commit comments