Skip to content

Commit 5909a80

Browse files
author
Juan Osorio
committed
MarkdownTextBlock: Expose MarkdownDocument as a readonly property
1 parent 6dafb91 commit 5909a80

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.Renderers;
66
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements;
77
using Markdig;
8+
using Markdig.Syntax;
89

910
namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock;
1011

@@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control
3031
typeof(MarkdownTextBlock),
3132
new PropertyMetadata(null, OnTextChanged));
3233

34+
private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register(
35+
nameof(MarkdownDocument),
36+
typeof(MarkdownDocument),
37+
typeof(MarkdownTextBlock),
38+
new PropertyMetadata(null));
39+
3340
public MarkdownConfig Config
3441
{
3542
get => (MarkdownConfig)GetValue(ConfigProperty);
@@ -42,6 +49,12 @@ public string Text
4249
set => SetValue(TextProperty, value);
4350
}
4451

52+
public MarkdownDocument? MarkdownDocument
53+
{
54+
get => (MarkdownDocument)GetValue(MarkdownDocumentProperty);
55+
private set => SetValue(MarkdownDocumentProperty, value);
56+
}
57+
4558
public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;
4659

4760
internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
@@ -102,8 +115,8 @@ private void ApplyText(bool rerender)
102115

103116
if (!string.IsNullOrEmpty(Text))
104117
{
105-
var markdown = Markdown.Parse(Text, _pipeline);
106-
_renderer.Render(markdown);
118+
this.MarkdownDocument = Markdown.Parse(Text, _pipeline);
119+
_renderer.Render(this.MarkdownDocument);
107120
}
108121
}
109122
}

0 commit comments

Comments
 (0)