Selectable TextBlock or a TextBox with formatted text in WPF

独自空忆成欢 提交于 2020-01-04 05:52:47

问题


I have a situation where I need to show a formatted text (normal, bold, highlighted) and should also be selectable so that user can copy the text.

I have used textblock where i can apply multiple formattings using Inline content flow elements but unfortunately it's text is not selectable.

Whereas Textbox allows to select text and copy to clipboard, it does not allow me to format text.

Is there anything I am missing or I'll have to build a custom control?


回答1:


I'm not sure how much style you're wanting to apply, but I find the following site to be useful to determine the best way to use Silverlight controls: http://samples.msdn.microsoft.com/Silverlight/SampleBrowser/index.htm#/

This specific URL has some information on how to style a Textbox: http://samples.msdn.microsoft.com/Silverlight/SampleBrowser/index.htm#/?sref=TextBoxSnippet




回答2:


You can use RichTextBox. It control is selectable and support formatted tex.



来源:https://stackoverflow.com/questions/2898576/selectable-textblock-or-a-textbox-with-formatted-text-in-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!