From 043158961524709251e022dcb29d8fbc5a487e79 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 22 Jul 2022 16:33:37 +0200 Subject: [PATCH] Fix images loading, minor .csproj tweaks --- .../ViewModels/SamplePageViewModel.cs | 10 ++++++---- .../MvvmSampleUwp/Controls/DocumentationBlock.cs | 16 ++++++++++++++++ samples/MvvmSampleUwp/MvvmSampleUwp.csproj | 12 ++++++++---- samples/MvvmSampleUwp/Shell.xaml | 2 +- .../INotifyPropertyChangedAttributePage.xaml | 2 +- .../Views/ObservablePropertyAttributePage.xaml | 2 +- .../Views/RelayCommandAttributePage.xaml | 2 +- .../Views/SourceGeneratorsPage.xaml | 2 +- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/samples/MvvmSample.Core/ViewModels/SamplePageViewModel.cs b/samples/MvvmSample.Core/ViewModels/SamplePageViewModel.cs index fb6b20d..d0a7fa1 100644 --- a/samples/MvvmSample.Core/ViewModels/SamplePageViewModel.cs +++ b/samples/MvvmSample.Core/ViewModels/SamplePageViewModel.cs @@ -64,15 +64,17 @@ public class SamplePageViewModel : ObservableObject // Skip if the loading has already started if (LoadDocsCommand.ExecutionTask is not null) return; - string path = Path.Combine("Assets", "docs", $"{name}.md"); + string directory = Path.GetDirectoryName(name); + string filename = Path.GetFileName(name); + string path = Path.Combine("Assets", "docs", directory, $"{filename}.md"); using Stream stream = await FilesServices.OpenForReadAsync(path); using StreamReader reader = new(stream); string text = await reader.ReadToEndAsync(); - // Drop image links - string trimmedText = Regex.Replace(text, @"[ \r\n]+?!\[[^]]+\]\([^)]+\)[ \r\n]+?", string.Empty); + // Fixup image links + string fixedText = Regex.Replace(text, @"!\[[^\]]+\]\(([^ \)]+)(?:[^\)]+)?\)", m => $"![]({m.Groups[1].Value})"); - Texts = MarkdownHelper.GetParagraphs(trimmedText); + Texts = MarkdownHelper.GetParagraphs(fixedText); OnPropertyChanged(nameof(GetParagraph)); } diff --git a/samples/MvvmSampleUwp/Controls/DocumentationBlock.cs b/samples/MvvmSampleUwp/Controls/DocumentationBlock.cs index a3a2051..5f89690 100644 --- a/samples/MvvmSampleUwp/Controls/DocumentationBlock.cs +++ b/samples/MvvmSampleUwp/Controls/DocumentationBlock.cs @@ -8,6 +8,7 @@ using Microsoft.Toolkit.Uwp.UI.Controls; using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media.Imaging; #nullable enable @@ -40,6 +41,7 @@ public sealed class DocumentationBlock : ContentControl markdownTextBlock = (MarkdownTextBlock)GetTemplateChild("PART_MarkdownTextBlock")!; markdownTextBlock.LinkClicked += MarkdownTextBlock_LinkClicked; + markdownTextBlock.ImageResolving += MarkdownTextBlock_ImageResolving; } /// @@ -57,6 +59,20 @@ public sealed class DocumentationBlock : ContentControl } } + /// + /// Handles an image being resolved and loads images from the local assets. + /// + /// The source control. + /// The input arguments. + private void MarkdownTextBlock_ImageResolving(object sender, ImageResolvingEventArgs e) + { + if (e.Url?.Contains("source-generator-visualization.png") == true) + { + e.Image = new BitmapImage(new Uri("ms-appx:///Assets/docs/images/source-generator-visualization.png")); + e.Handled = true; + } + } + /// /// Gets or sets the representing the text to display. /// diff --git a/samples/MvvmSampleUwp/MvvmSampleUwp.csproj b/samples/MvvmSampleUwp/MvvmSampleUwp.csproj index f4175b4..fbc173e 100644 --- a/samples/MvvmSampleUwp/MvvmSampleUwp.csproj +++ b/samples/MvvmSampleUwp/MvvmSampleUwp.csproj @@ -534,19 +534,23 @@ PreserveNewest - Assets\docs\Overview.md + Assets\docs\generators\Overview.md PreserveNewest - Assets\docs\ObservablePropertyAttribute.md + Assets\docs\generators\ObservableProperty.md PreserveNewest - Assets\docs\RelayCommandAttribute.md + Assets\docs\generators\RelayCommand.md PreserveNewest - Assets\docs\INotifyPropertyChangedAttribute.md + Assets\docs\generators\INotifyPropertyChanged.md + PreserveNewest + + + Assets\docs\images\source-generator-visualization.png PreserveNewest diff --git a/samples/MvvmSampleUwp/Shell.xaml b/samples/MvvmSampleUwp/Shell.xaml index 608bc53..f525606 100644 --- a/samples/MvvmSampleUwp/Shell.xaml +++ b/samples/MvvmSampleUwp/Shell.xaml @@ -97,7 +97,7 @@ - + diff --git a/samples/MvvmSampleUwp/Views/ObservablePropertyAttributePage.xaml b/samples/MvvmSampleUwp/Views/ObservablePropertyAttributePage.xaml index 6d6f0e2..ec9b049 100644 --- a/samples/MvvmSampleUwp/Views/ObservablePropertyAttributePage.xaml +++ b/samples/MvvmSampleUwp/Views/ObservablePropertyAttributePage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/samples/MvvmSampleUwp/Views/RelayCommandAttributePage.xaml b/samples/MvvmSampleUwp/Views/RelayCommandAttributePage.xaml index 457d498..eddda47 100644 --- a/samples/MvvmSampleUwp/Views/RelayCommandAttributePage.xaml +++ b/samples/MvvmSampleUwp/Views/RelayCommandAttributePage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - + diff --git a/samples/MvvmSampleUwp/Views/SourceGeneratorsPage.xaml b/samples/MvvmSampleUwp/Views/SourceGeneratorsPage.xaml index 6043014..c7c55c0 100644 --- a/samples/MvvmSampleUwp/Views/SourceGeneratorsPage.xaml +++ b/samples/MvvmSampleUwp/Views/SourceGeneratorsPage.xaml @@ -11,7 +11,7 @@ mc:Ignorable="d"> - +