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

时间:2014-02-19 12:55:01

标签: 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>

如果我将Window更改为UserControl,它会起作用。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:6)

在Xaml中:您需要添加RequestNavigate

                    <TextBlock >
                        Please email <Hyperlink NavigateUri="mailto:test@test.co.uk"  RequestNavigate="Hyperlink_RequestNavigate">test@test.cp.uk</Hyperlink>
                    </TextBlock>

在代码背后:

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