如何让NavigateUri在WPF窗口中工作?

Kei*_*son 0 c# wpf xaml

mailto链接在此示例中不起作用:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock>Please email
        <Hyperlink NavigateUri="mailto:test@test.co.uk">test@test.cp.uk</Hyperlink>
    </TextBlock>
</Window>
Run Code Online (Sandbox Code Playgroud)

如果我将Window更改为UserControl,它可以工作.

有人可以帮忙吗?

小智 6

在Xaml中:您需要添加RequestNavigate

                    <TextBlock >
                        Please email <Hyperlink NavigateUri="mailto:test@test.co.uk"  RequestNavigate="Hyperlink_RequestNavigate">test@test.cp.uk</Hyperlink>
                    </TextBlock>
Run Code Online (Sandbox Code Playgroud)

代码背后:

    private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
    {
        Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
        e.Handled = true;
    }
Run Code Online (Sandbox Code Playgroud)