【发布时间】:2011-06-20 11:23:18
【问题描述】:
我有一个包含文本和超链接的 WPF 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);
【问题讨论】:
-
在您的问题中粘贴相关代码,而不是必须下载的演示代码链接,这将提高您获得好答案的机会。
标签: c# .net wpf hyperlink richtextbox