【问题标题】:WinRt: How to add and remove links on RichEditBox?WinRt:如何在 RichEditBox 上添加和删除链接?
【发布时间】:2014-12-31 02:21:53
【问题描述】:

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

【问题讨论】:

    标签: c# windows-runtime rtf uwp


    【解决方案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 = "";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      相关资源
      最近更新 更多