首页 文章

RichTextBox超链接

提问于
浏览
2

我有一个包含文本和超链接的WPF richtextbox . 我想按下按钮时更改所选超链接的字体大小 . 我遇到的问题是我无法从richtextbox选择中获取所选的超链接 .

最好的祝福

玛丽安

PS . 我在这里上传了一个演示:http://cid-6d5e36974c8e12a8.office.live.com/self.aspx/RTB%20Hyperlink/RTBDemo.zip

PS2 . 在插入位置添加到rtb的超链接:

Run hyper = new Run("SampleLink");
Hyperlink hp = new Hyperlink(hyper);
hp.Click += new RoutedEventHandler(hp_Click);
TextBlock tb = new TextBlock();
tb.FontSize = 10;
tb.Inlines.Add(hp);
using (rtb.DeclareChangeBlock())
{
    TextPointer tp = rtb.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward);
    InlineUIContainer inlineUIContainer = new InlineUIContainer(tb, tp);
    rtb.CaretPosition = inlineUIContainer.ElementEnd;
}
rtb.IsDocumentEnabled = true;

PS3 . 设置字体:

TextRange text = new TextRange(rtb.Selection.Start, rtb.Selection.End);
text.ApplyPropertyValue(TextElement.FontSizeProperty, 14.00);

解决:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/23fcf1b7-8708-40ca-b3b0-658a96a795eb/#b2f32824-fab6-45cc-8c81-7c26986b12bf

1 回答

相关问题