开发者

Creating a mailto: hyperlink in Silverlight Out Of Browser app

Is there a way to create a mailto: hyperlink in a Silverlight 4 OOB app? Thanks!

Edit: based on some of the discussion, an acceptable a开发者_开发问答nswer would be a different way than using the HyperlinkButton, or a way to use the HyperlinkButton without having the extra popup in IE.


Ideally it would have been nice of you to post some code, as I have no idea whether the email address is known/determined at design-time or run-time, but nonetheless:

In XAML:

<HyperlinkButton x:Name="mailButton" NavigateUri="mailto:somedude@example.com" TargetName="_blank"></HyperlinkButton>

In C#:

HyperlinkButton hbtn = new HyperlinkButton();
hbtn.Name = "mailButton";
hbtn.TargetName = "_blank";
hbtn.NavigateUri = new Uri("mailto:somedude@example.com"); 
parent.Controls.Add(hbtn);

In a situation in which you don't know the email address at design time, it's relatively straightforward to assign the value of the NavigateUri property within a method.


I posted a solution to this issue on CodeProject http://www.codeproject.com/Answers/383879/Silverlight-mailto-HyperlinkButton-always-opens-an#answer2

Essentially, instead of using the default behaviour add a click event and then call javascript location.href. This stops the extra browser window opening.

private void TestLink_Click(object sender, RoutedEventArgs e)
{
     //Only run the click event if in browser because this will not work OOB
     if (Application.Current.IsRunningOutOfBrowser)
         return;

     var cmd = String.Format("location.href='mailto:test@test.com?subject=blah&body=something';",

     HtmlPage.Window.Eval(cmd);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜