WinRt:如何在RichEditBox上添加和删除链接?

时间:2014-11-04 08:54:02

标签: c# windows-runtime rtf uwp

我花了一些时间研究这些问题:如何将RichEditBox中的选择转换为超链接以及如何再次删除此链接。

1 个答案:

答案 0 :(得分:1)

解决方案很简单。但是需要考虑一些变通方法:

public void InsertLink(RichEditBox control, string url) 
{
  //Check some conditions - else property assignment crashes
  if (string.IsNullOrEmpty(url)) return; 
  if (string.IsNullOrEmpty(control.Document.Selection.Text)) return; 
  control.Document.Selection.Link = "\"" + url + "\"";
}

public void RemoveLink(RichEditBox control) 
{
  //Can only set Link to empty string, if a link is assigned, 
  //else property assignment crashes
  if (string.IsNullOrEmpty(control.Document.Selection.Link)) return; 
  control.Document.Selection.Link = "";
}
相关问题