I am working on a wpf app, and I have a Customer Information section where I can record my customer information. In this section, I use a textbox recording customer's email address. But now I want to make the email address hyperlink and link the email address via Outlook email, say, if I click the email address, it opens the outlook email automatically so that I can send email via outlook. Thanks.
What I want is a Label or Textblock whose text is Email on the left (do not need to bind to the text in the textbox), a Textbox on the right where you can type an email address. After you type a valid email address in the textbox, you can click the email address, and it will open outlook automatically. In the To field of outlook, the email address is what you typed in.(The comments are so long in last question, so I make it a new question, the old question link is link email address and send email via outlook
<TextBlock Text="Email" Grid.Row="11" x:Name="lblEmail" VerticalAlignment="Top"/>
<TextBox Grid.Column="1" Grid.Row="11" x:Name="txtEmail" VerticalAlignment="Top"
TextDecorations="UnderLine" Foreground="Blue" Text="{Binding
Email, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True, NotifyOnValidationError=True}">
</TextBox>
you can try code XAML
code behind
from : https://social.msdn.microsoft.com/Forums/vstudio/en-US/dcbaaced-97b3-4276-bf95-960e77cb6c03/how-to-launch-default-mail-client-in-wpf-applications?forum=wpf
OK, let's have another go... first we have a
TextBox
that the user enters an e-mail address into:Then we have a
Hyperlink
object whoseNavigateUri
property is data bound to theTextbox.Text
field of theEmailTextBox
object:Then we have the
RequestNavigateEvent
handler that validates the e-mail address (Regular expression was taken from this post):Now, I still haven't been able to test any of this, so you might have to fix a couple of little errors yourself, but this is the roughly what you have to do. Feel free to add comments, but lets not make the comment section bigger than the question section this time. ;)
UPDATE >>>
Ok, so the problem was that the
hyperlink.NavigateUri
is in fact aUri
object and not astring
so we need to callToString()
on it.Just in case you need it, you can replace the line in your
Hyperlink_RequestNavigate
handler with this line to set the subject of the e-mail:This can be further extended to add part (or all) of the body too: