简体   繁体   English

RichTextBox超链接

[英]RichTextBox Hyperlink

I have a WPF richtextbox that contains text and hyperlinks. 我有一个WPF richtextbox ,其中包含文本和超链接。 I want to change the font size for the selected hyperlink when i press a button. 我想在按下按钮时更改所选超链接的字体大小。 The problem that i have is that i am not able to get the selected hyperlink from the richtextbox selection. 我的问题是我无法从Richtextbox选择中获取所选的超链接。

Best Regards 最好的祝福

Marian 玛丽安

PS. PS。 I've uploaded a demo here: http://cid-6d5e36974c8e12a8.office.live.com/self.aspx/RTB%20Hyperlink/RTBDemo.zip 我在这里上传了一个演示: http : //cid-6d5e36974c8e12a8.office.live.com/self.aspx/RTB%20Hyperlink/RTBDemo.zip

PS2. PS2。 Adding hyperlink to rtb at caret position: 在插入符号位置向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. PS3。 Setting font: 设置字体:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM