diff --git a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs index b3b984797..efba3cb4b 100644 --- a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs +++ b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs @@ -54,7 +54,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE { if (d is MarkdownTextBlock self && e.NewValue != null) { - self.ApplyText(self.Text, true); + self.ApplyText(true); } } @@ -87,16 +87,20 @@ private void ApplyConfig(MarkdownConfig config) } } - private void ApplyText(string text, bool rerender) + private void ApplyText(bool rerender) { - var markdown = Markdown.Parse(text, _pipeline); if (_renderer != null) { if (rerender) { _renderer.ReloadDocument(); } - _renderer.Render(markdown); + + if (!string.IsNullOrEmpty(Text)) + { + var markdown = Markdown.Parse(Text, _pipeline); + _renderer.Render(markdown); + } } } @@ -109,7 +113,7 @@ private void Build() _renderer = new WinUIRenderer(_document, Config); } _pipeline.Setup(_renderer); - ApplyText(Text, false); + ApplyText(false); } } } diff --git a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs index 19eef0a75..2c7db300d 100644 --- a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs +++ b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs @@ -131,4 +131,22 @@ public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() Assert.IsFalse(component.IsLoaded); } + + [UIThreadTestMethod] + public async Task MarkdownTextBlockEmptyTextValueTest() + { + var component = new MarkdownTextBlock + { + Config = new() + }; + + Assert.IsNotNull(component); + Assert.IsFalse(component.IsLoaded); + + await LoadTestContentAsync(component); + Assert.IsTrue(component.IsLoaded); + + await UnloadTestContentAsync(component); + Assert.IsFalse(component.IsLoaded); + } }