WPF allowing users to format TextBlock with bold/italics/underlining, etc - c#

I am creating a template where users will be able to type in text and would like to make it so they can format it. Preferably by methods similar to Word where they can select the text and then click a button, but I would be OK with allowing them to put the tags in there also, like < b > < / b>, etc as long as it formats properly.
Is there an easy way to do this using Inlines at runtime?

I definitely recommend you having a look at RichTextBox:
The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#. (Microsoft docs)
Here is a pretty indepth tutorial of using RichTextBox to create a text editor, using buttons allowing the user to changes properties such as font size, bold, colour, etc... :
https://wpf-tutorial.com/rich-text-controls/how-to-creating-a-rich-text-editor/.

Related

UP simple Way to store/retrieve formatted Text

currently, I'm using Richeditbox in my to edit and display formatted text in App. there a now a lot of RichEditBoxes. because its the goal of the App, to show a list of formatted text blocks with different Content. The Performance is really slow and the space in DB is great, I'm storing the text in RTF-format in blobs.
What is the easiest way to show simple formatted Text (eg bold, italic)? I never found a quite sample?
If you just want to display formatted text you have two options.
RichTextBlock is a TextBlock-like counterpart of RichEditBox. It is however more performant as it just displays the content and does not offer editing.
Alternatively there is a MarkdownTextBlock control in the UWP Community Toolkit, which can display simple formatted text in the Markdown format.

Integrating Visio exported XAML into Silverlight application

It is possible to export Microsoft Visio drawings as a Website containing Silverlight content. This is described on this blog-post.
The output of such an export are the following:
xaml_1.xaml (contains the structure of the control)
data.xml (contains all text content such as labels, etc)
several java-script files
*.htm pages with a Silverlight container
other files such as *.css and images
I would like to integrate the exported XAML code into another existing Silverlight application. I found this blog-post telling me how to load XAML code dynamically during runtime.
What I would like to know is how to "merge" the XAML-file and the data.xml and how I can get a reference to the items of the XAML code, in order to change certain texts...
In the associated xaml js file (eg xaml_1.js) there's a handleMouseUp function that reads the shape ID from the (XAML) 'name' string and then calls OnShapeClick in frameset.js. This method, which is common to all of the js-based Save as web output types, then calls other methods to populate the details table or retrieve hyperlinks found in data.xml. If you have a look at the FindShapeXML function in frameset.js you'll see that it gets the appropriate data based on the page and shape IDs (note that shape IDs are unique to a page as per Visio itself).
In terms of creating data-bound or dynamic shape text, one workaround for the glyphs issue that #slfan highlights is prevent the text from being output. For example, prior to running Save As Web in Visio, you could loop through all of the shapes and set their HideText ShapeSheet cell to true. This will prevent all of the glyphs xaml being generated and you'll still have access to the text string in data.xml. I guess you wouldn't then benefit from the correct font scaling, but it depends on your scenario. If it was really important to get the scale right then you could parse the RenderTransform attribute (which is described in attribute syntax rather than property element syntax) of the glyph elements.
Glyphs are there (I'm guessing) because it mirrors how Visio works in the application ie in Visio you can select individual characters within a shape's text and apply different fonts and formatting, but if you don't need that, I'd be tempted to ditch the glyphs collection and just use a TextBlock as #slfan suggests.
I think you have to tweak the generated XAML a little bit. Unfortunately Visio generates glyphs for every single character. If you want to change the text at runtime, you will have to remove this glyphs and add the required controls (e.g. TextBlock) yourself.
You can load the XAML into Silverlight with XamlReader.Load. A good description you find here: http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx.
All JavaScript and HTML files you can ignore, the XML-file you need to identify your controls. The ID's in the XML refer to the corresponding elements in the XAML-file.

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

Selectable TextBlock or a TextBox with formatted text in WPF

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.

Categories

Resources