在 WPF 应用程序的默认电子邮件处理程序中打开新电子邮件的链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23020377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Link to Open New Email Message in Default E-mail Handler in WPF Application
提问by user3342256
My goal is basic: Have a label/texblock what-have-you on a WPF form that is stylized to look like a link. When clicked, the control should open a new e-mail composition window in the user's default e-mail app. The code to actually open the new e-mail window seems trivial:
我的目标是基本的:在 WPF 表单上有一个标签/texblock what-have-you,它的样式看起来像一个链接。单击时,控件应在用户的默认电子邮件应用程序中打开一个新的电子邮件撰写窗口。实际打开新电子邮件窗口的代码似乎微不足道:
Process.Start("mailto:[email protected]?subject=SubjectExample&body=BodyExample ");
However I'm having trouble with two pieces:
但是我在两件事情上遇到了麻烦:
- Binding the "new message open" action to a label click event.
- Stylizing the label so that it looks exactly like a default WPF hyperlink.
- 将“新消息打开”操作绑定到标签点击事件。
- 样式化标签,使其看起来与默认的 WPF 超链接完全相同。
回答by Reed Copsey
If you want the style to be like a hyperlink, why not just use one directly?
如果你想让样式像一个超链接,为什么不直接使用一个呢?
<TextBlock>
<Hyperlink NavigateUri="mailto:[email protected]?subject=SubjectExample&body=BodyExample" RequestNavigate="OnNavigate">
Click here
</Hyperlink>
</TextBlock>
Then add:
然后加:
private void OnNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(e.Uri.AbsoluteUri);
e.Handled = true;
}
回答by OliverAssad
You can do this entirely in XAML Use Expression interactions to call the link mentioned above
您可以完全在 XAML 中使用表达式交互来调用上面提到的链接
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<Label Content="Send Email">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<ei:LaunchUriOrFileAction Path="mailto:[email protected]" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>

