-
Notifications
You must be signed in to change notification settings - Fork 26
How to customise linkaction
whistyun edited this page Jan 3, 2021
·
1 revision
Markdown.Avalonia.Markdown
class has HyperlinkCommand
property.
HyperlinkCommand
property is ICommand
type allow customise action when user click hyperlink.
Xaml
<!-- xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia" -->
<Window.Resources>
<local:MyLinkCommand x:Key="myLinkCommand"/>
</Window.Resources>
...
<md:MarkdownScrollViewer>
<md:MarkdownScrollViewer.Engine>
<md:Markdown
HyperlinkCommand="{StaticResource myLinkCommand}"
/>
</md:MarkdownScrollViewer.Engine>
</md:MarkdownScrollViewer>
MyLinkCommand.cs
public class MyLinkCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) => true;
// parameter is only string.
// The url described in markdown is passed to parameter as it is.
// relative path remains relative path, absolute path remain absolute path.
public void Execute(object parameter)
{
var urlTxt = (string)parameter;
Markdown.Avalonia.Utils.DefaultHyperlinkCommand.GoTo("http://example.com");
}
}