Repository navigation
Image loading priority
whistyun edited this page Oct 24, 2021
·
1 revision
MarkdownScrollViewer attempt to load image from resource or filesystem.
The below list is an image loading rule of MarkdownScrollViewer
- If you set absolute path, MdXaml read as it is.
- If you set relative path, MdXaml read from resource.
- If '2' is failed, MdXaml read from
AssetPathRoot(In default, current directory). - If '3' is failed, MdXaml give up.
MarkdownScrollViewer implements IUriContext. MarkdownScrollViewer try to make an absolute path based from BaseUri and load the image from the resource.
.csproj
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
...
<ItemGroup>
<Resource Include="Assets\ResourceImage1.png" />
<Resource Include="Assets\img\ResourceImage2.png" />
</ItemGroup>
</Project>MainWindow.xaml
<Window x:Class="image_load_example.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
Title="MainWindow" Height="450" Width="800">
<mdxam:MarkdownScrollViewer xml:space="preserve">


</mdxam:MarkdownScrollViewer>
</Window>MarkdownScrollViewer.AssetPathRoot, which is set as current directory in default, is also used base path to make an absolute path.
This property is affected by the Source Property.
Source property changing causes AssetPathRoot changing.
.xaml.cs
// MarkdownScrollViewer Markdownview;
Debug.Print(Markdownview.Engine.AssetPathRoot); // => Environment.CurrentDirectory
Markdownview.Source = new Uri("https://raw.githubusercontent.com/whistyun/MdXaml/master/docs/index.md");
Debug.Print(Markdownview.Engine.AssetPathRoot); // => https://raw.githubusercontent.com/whistyun/MdXaml/master/docs/index.md