2013-08-02 89 views
0

我嘗試使用此代碼打開電子郵件客戶端(Outlook或Gmail,具體取決於用戶的偏好)。指向電子郵件地址的超鏈接

XAML:

<TextBlock Margin="0,5,0,0" > 
     <Hyperlink RequestNavigate="HandleRequestNavigate" Foreground="{StaticResource EnableColorSolid}" NavigateUri="http://[email protected]"> 
        [email protected] 
     </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; 
    } 

但它不工作。任何想法爲什麼?我認爲這個鏈接有問題,但我不知道它是什麼。

+0

使用 「電子郵件地址」 的不是 「http://」 – Vishal

回答

0

使用mailto鏈接:

<TextBlock Margin="0,5,0,0" > 
     <Hyperlink RequestNavigate="HandleRequestNavigate" 
      Foreground="{StaticResource EnableColorSolid}" 
      NavigateUri="mailto:[email protected]"> 
        [email protected] 
     </Hyperlink> 
</TextBlock> 
+0

這隻會使用默認的電子郵件應用程序。如果您想使用Gmail或任何其他網絡電子郵件提供商,則必須使用'System.Net.Mail'命名空間通過SMTP發送電子郵件。您可以點擊超鏈接,處理導航,然後調用您的電子郵件功能... – Nick

相關問題