-
Notifications
You must be signed in to change notification settings - Fork 37
Image loading priority
whistyun edited this page Oct 24, 2021
·
1 revision
![attrnm](path/to/image.png)
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">
![img](Assets/ResourceImage1.png)
![img](Assets/img/ResourceImage2.png)
</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