【问题标题】:How do you get NavigateUri to work in a WPF window?如何让 NavigateUri 在 WPF 窗口中工作?
【发布时间】:2014-02-19 12:55:00
【问题描述】:

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,它会起作用。

谁能帮忙?

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

在 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;
    }

【讨论】:

  • 辛苦了。感谢您的帮助。
  • 我得到异常“找不到程序”。
  • +1 如果您收到异常提示系统找不到指定文件,请使用Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true }); 代替上面的行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-29
  • 2019-06-30
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 2010-09-30
  • 1970-01-01
相关资源
最近更新 更多