我想要在RichTextBox中启用电子邮件地址,我在文本中搜索带有@的单词,并希望在段落中添加EmailComposeTask。这可能吗?
if (word.Contains("@"))
{
???
paragraph.Inlines.Add(????);
}
答案 0 :(得分:1)
您可以执行以下操作:
foreach (var word in text)
{
if (word.Contains("@")
{
var link = new Hyperlink
{
Command = new EmailComposeCommand(),
CommandParameter = word
};
link.Inlines.Add(new Run { Text = word });
paragraph.Inlines.Add(link
}
else
{
paragraph.Inlines.Add(new Run { Text = word });
}
}
public class ClickToCallCommand : ICommand
{
public bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(parameter.ToString());
}
public void Execute(object parameter)
{
var ect = new EmailComposeTask
{
To = parameter.ToString()
};
ect.Show();
}
public event EventHandler CanExecuteChanged;
}
根据需要添加适当的错误处理等。