我写了一些代码,它们在RTB WPF控件中写入的文本中动态着色“关键字”。我想改变像维基百科这样的超链接中的着色。但是当我使用那段代码时:
new struct Tag
{
public TextPointer StartPosition;
public TextPointer EndPosition;
public string Word;
}
List<Tag> m_tags = new List<Tag>();//list with key words which may transform to hyperlinks
//TextInput is RTB
private void TextFormating()
{
TextInput.TextChanged -= this.TextChangedEventHandler;
TextInput.IsEnabled = true;
for(int i=0; i<m_tags.Count;i++)
{
Hyperlink link = new Hyperlink(m_tags[i].StartPosition,m_tags[i].EndPosition);
link.IsEnabled = true;
link.NavigateUri = new Uri(@"www.google.com");
link.RequestNavigate += new RequestNavigateEventHandler(link_RequestNavigate);
}
m_tags.Clear();
TextInput.TextChanged += this.TextChangedEventHandler;
}
我创建超链接的行显示异常“结束后不会开始”。
感谢您的任何想法。