I try to use the Tag in C# WPF to build a link that openes the standard email client.
This is my WPF Code:
<TextBlock>
<Hyperlink NavigateUri="mailto:[email protected]?subject=SubjectExample&body=BodyExample" RequestNavigate="Hyperlink_RequestNavigate">
Click here
</Hyperlink>
</TextBlock>
This works so far very fine. Now i want to make it a little more dynamically, so i tried to bind a variable with all necessary information:
<TextBlock>
<Hyperlink NavigateUri="{Binding MyValue}" RequestNavigate="Hyperlink_RequestNavigate">
Click here
</Hyperlink>
</TextBlock>
The Public Value MyValue looks like this:
public string MyValue{
get { return "mailto:" + myEmail + "?subject=" + mySubject + "&body=TEST"; }
Everything works fine except the Body Text. "TEST" should be printed but it isnt. It has been printed in my first try without binding but not in this case
Am i doing something wrong?
Try to escape the values using the Uri.EscapeDataString
method:
public string MyValue
{
get
{
return String.Format("mailto:{0}?subject={1}&body=TEST",
Uri.EscapeDataString(myEmail),
Uri.EscapeDataString(mySubject));
}
}