超链接到电子邮件地址

时间:2013-08-02 10:18:12

标签: c# wpf email hyperlink

我尝试使用此代码打开电子邮件客户端(Outlook或Gmail,具体取决于用户偏好)。

XAML:

    <TextBlock  Margin="0,5,0,0"  >
         <Hyperlink  RequestNavigate="HandleRequestNavigate" Foreground="{StaticResource EnableColorSolid}" NavigateUri="http://info@kramerel.com">
                   info@kramerel.com
         </Hyperlink>
    </TextBlock>

代码:

 private void HandleRequestNavigate(object sender, RequestNavigateEventArgs e)
    {
        string navigateUri = (sender as Hyperlink).NavigateUri.ToString();
        // if the URI somehow came from an untrusted source, make sure to
        // validate it before calling Process.Start(), e.g. check to see
        // the scheme is HTTP, etc.
        Process.Start(new ProcessStartInfo(navigateUri));
        e.Handled = true;
    }

但它不起作用。知道为什么吗?我认为链接有问题,但我不知道它是什么。

1 个答案:

答案 0 :(得分:0)

使用mailto链接:

<TextBlock  Margin="0,5,0,0"  >
         <Hyperlink  RequestNavigate="HandleRequestNavigate" 
          Foreground="{StaticResource EnableColorSolid}" 
          NavigateUri="mailto:info@kramerel.com">
                   info@kramerel.com
         </Hyperlink>
</TextBlock>