From 5909a80745967977b3125c61914b8db5b8941ef3 Mon Sep 17 00:00:00 2001 From: Juan Osorio Date: Tue, 26 Nov 2024 15:01:09 -0800 Subject: [PATCH] MarkdownTextBlock: Expose MarkdownDocument as a readonly property --- .../src/MarkdownTextBlock.xaml.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs index eef90cf74..01e05751f 100644 --- a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs +++ b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs @@ -5,6 +5,7 @@ using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.Renderers; using CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements; using Markdig; +using Markdig.Syntax; namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock; @@ -30,6 +31,12 @@ public partial class MarkdownTextBlock : Control typeof(MarkdownTextBlock), new PropertyMetadata(null, OnTextChanged)); + private static readonly DependencyProperty MarkdownDocumentProperty = DependencyProperty.Register( + nameof(MarkdownDocument), + typeof(MarkdownDocument), + typeof(MarkdownTextBlock), + new PropertyMetadata(null)); + public MarkdownConfig Config { get => (MarkdownConfig)GetValue(ConfigProperty); @@ -42,6 +49,12 @@ public string Text set => SetValue(TextProperty, value); } + public MarkdownDocument? MarkdownDocument + { + get => (MarkdownDocument)GetValue(MarkdownDocumentProperty); + private set => SetValue(MarkdownDocumentProperty, value); + } + public event EventHandler? OnLinkClicked; internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri)); @@ -102,8 +115,8 @@ private void ApplyText(bool rerender) if (!string.IsNullOrEmpty(Text)) { - var markdown = Markdown.Parse(Text, _pipeline); - _renderer.Render(markdown); + this.MarkdownDocument = Markdown.Parse(Text, _pipeline); + _renderer.Render(this.MarkdownDocument); } } }