我刚刚发现自己面临一个新的挑战:使用像纯文本处理更像Web的字处理器.为此设计一个很好的框架是我无法等待的开始,但我确实需要知道GUI端的可能性(它可能会有很多GUI挑战).
所以基本的东西,我需要某种控制,我可以使我的文本的部分可点击/鼠标覆盖.
我是WPF的新手,不知道如何做到这一点.有谁知道如何制作这个?有例子吗?对此有控制吗?
提前致谢
编辑:
我发现了一些使用richtextbox的方法:
// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
// Add paragraphs to the FlowDocument.
Hyperlink myLink = new Hyperlink();
myLink.Inlines.Add("hyperlink");
myLink.NavigateUri = new Uri("http://www.stackoverflow.com");
// Create a paragraph and add the Run and hyperlink to it.
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add("check this link out: ");
myParagraph.Inlines.Add(myLink);
myFlowDoc.Blocks.Add(myParagraph);
// Add initial content to the RichTextBox.
richTextBox1.Document = myFlowDoc;
Run Code Online (Sandbox Code Playgroud)
我现在在我的文本框中得到一个很好的超链接...除非我点击它,没有任何反应.我在这里失踪了什么?
我有一个 RichTextbox,我想添加按钮控件并使其启用点击。
不幸的是,当您添加它时,它会自动禁用
这似乎是 FlowDocument 的限制,但因为这是一个非常简单的要求。我发现很难相信没有干净的方法可以启用它。
这是通过创建一个扩展 FlowDocument 的新控件的解决方案,但我想避免它。
解决方法的描述 是否有一种干净的方法来完成此操作?
<RichTextBox x:Name="txt1" HorizontalAlignment="Left" Height="183" Margin="36,10,0,0" VerticalAlignment="Top" Width="508">
<FlowDocument IsEnabled="True">
<Paragraph LineHeight="1">
<Button Content="Button" Height="25" Width="93" Click="Button_Click_1"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
Run Code Online (Sandbox Code Playgroud)