Selectable TextBlock or a TextBox with formatted text in WPF - c#

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?

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

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

Related

WPF textblock which allows the selection of text

I have a TextBlock in my app that has text with some URLs in it. At the same time, I want the text to be selectable and copyable. If I use the TextBox element I loose the ability to add Hyperlinks and if I use the TextBlock I loose the selection functionality.
Having all that said, what do you suggest to keep both the hyperlinks and the select (with mouse and keyboard) ability?
Edit: this application is a chat app, and I want the incoming message to be selectable while the URL are clickable.
Not sure but perhaps you can use RichTextBox. See: Adding hyperlink in textbox.
You will have to manage to find links when the user type one and modify the text in accordance (inserting an hyperlink) with the user text. Or add a way, like a ContextualMenu, to offer the user to add an hyperlink.
I'm not sure you can find a control that do exactly what you want. Good luck!
The Webbrowser control will allow text selection and hyperlinks.
You can do something like this:
<Label>
<Hyperlink NavigateUri="bob#contoso.com">
<Run Text="bob#contoso.com"/>
</Hyperlink>
</Label>
You can style appropriately and add commands to Hyperlink if you want to actually navigate to that link when clicked

Show HTML Text in TextBlock-Control

I try to get HTML-Text in a TextBock without HTML-Tags. DO anyone know, if it is possible to show html-Text in a TextBlock Control? Have I to use a WebBrowser Control for this case. I use simple HTML-Tags to format Text like Textalignment or Textdecorations.
Here is a example of my HTML-Text:
Headline for TestingDescriptions
I think you can try two different approaches:
Simply display the HTML content in a WebBrowser control. This has
multiple disadvantages, such as not being able to be transparent,
and its performance can be quite disappointing.
Convert your HTML content to
XAML FlowDocument, which you can display natively in a TextBlock. You can find more information about how to convert
here.

Is it possible to have differently colored lines in multiline text box?

Is it possible to have differently colored lines in multiline text box?
I'm adding data to the text box and I want to clarify for the user different types of text by color.
How to do this if it's possible?
You can do this if you use a RichTextBox control. See the documentation here (particularly look at the Remarks and Examples sections). The standard TextBox does not offer this capability.
The standard Winforms textbox does not have this ability (and adding it would be troublesome).
You could look at using the System.Windows.Forms.RichTextBox as an alternative for this or one of the many commercial alternatives.
So depending on how you want the output, there's an browser/html control (basically a box), that you can pass a URL or a string of HTML, depending on what you're doing, you might want to use the RickTextBox - which has formatting commands - you could use regular expressions, or the offset of the text and then use a "set color" command on the text box with an IF structure.

RichText box has not displaying the large text in WPF with MVVM

How to display the large text in the richtextbox. I need to use with MVVM pattern.
Can anyone suggest me a wpf control to display large text or how to make the richtextbox to display entire content?
Richtextbox can display more than 1000 lines. I use the one for cat and it works just nice(with all the formatting and etc). May be you have vertical scroll OFF and you cant see the rest of the lines?! see Shoaib Shaikh answer with suggested properties values.
Rich text box can also have same properties to accept multiple lines as textbox does. in order to conditionally format some lines in red you will have to provide Flow document in RichTextbox. you can create flow document by xml. this is an article could be helpful
http://www.codeproject.com/KB/WPF/BindableWPFRichTextBox.aspx

looking for text control that is easy to data bind and text highlight wpf

I am looking for some control that can do following 2 :
1.highlight some of the text in different colors.
easy databind.
checked richtextbox - but it is hard to databind with it.
checked textbox but it problem to text hight light with it.
any suggestions
Use the RichTextBox - or even better the Extended RichTextBox here (it allows easy DataBinding): http://wpftoolkit.codeplex.com/wikipage?title=RichTextBox.
If you don't want to have to include another control you can create an AttachedProperty to make it possible to bind to the built in RichTextBox. Check this out here: http://michaelsync.net/2009/06/09/bindable-wpf-richtext-editor-with-xamlhtml-convertor

Categories

Resources