Does WPF Textbox respect Unicode BIDI controls like LRI/RLI? - wpf

I need to display English + Hebrew text mixed in a text box. I embed each language with the appropriate RLI/LRI/PDI controls but it seems that it doesn't make any difference. Depending on the content, things end up out of order, like if the BIDI controls are being ignored.
To check that my BIDI controls are placed correctly, I take the same text displayed in the textbox and put it in Clipboard. Pasting it to notepad or word displays the text in the expected order while on the textbox it isn't.
Can someone confirm if WPF textbox should respect these Unicode BIDI controls?
Am I missing any special setting on the textbox so it takes it into consideration?

Related

How to put ellipsis (...) in RichTextBox

I want to put an ellipsis (..) in the rich text box.
In normal TextBlock, TextTrimming="WordEllipsis" has a property that limits the length to allow ellipsis representation, but rich text boxes do not. And it should only be implemented as a rich textbox now. Text blocks are not allowed.
I'd like to trim by two or three lines and add an ellipsis (..) option. Is there any good way?
I want to show you how I'm using RichTextBox, but the reputation is low.
You don't
The ellipsis concept is, as stated by grek40, something that only works when displaying text.
As an example, say the ellipsis is displayed, and the user tries to partially select some text in your RichTextBox, including the ellipsis, what would the selected result be? You can't tell.
Maybe
Since an ellipsis is usually a replacement for a Scrollbar, hiding text instead of allowing you to access it by scrolling, you might be able to fake it by using a WPF Style.
Create a Style that displays an icon/picture of an ellipsis (placement is up to you) whenever the Scrollbar visibility trigger is triggered. You would need to disable the Scrollbar once the ellipsis is visible.
This obviously requires more effort than simply setting a property, and it can easily become a User Experience nightmare if not carefully implemented, so be warned.
Note: Another comment (by Walt Ritscher) linked to a similar question, the solution there is similar to this one.
Alternative Maybe
Another faked ellipsis could be achieved by using two different RichTextBox controls.
The first RichTextBox would have set ReadOnly to true. Trim your text to a maximum allowed length, and append an ellipsis and display it inside this first RichTextBox.
When the user need to edit the text hide the first RichTextBox and display a second RichTextBox that contains your entire text.

Masked TextBox with differing sized text

OK, I admit this is an unusual case! I need a masked TextBox in which groups of different characters are different sizes. The text has to be selectable as a single block for copy / paste / delete purposes.
I'm not sure how I'd go about this in WPF. Any ideas?
You want to change from TextBox to RichTextBox. In a richtextbox, you can control format of parts of the text.

.NET WinForms Localization - How to make control position based on length of text

I am working on localizing a WinForms application through satellite assemblies. The problem I am facing is that when I switch to some other language such as Japanese from English, the labels overlap (or go behind) the combo boxes because of the change in text. The change in text causes Label width to increase making them jump over to other controls.
Is there a way (maybe through Anchoring) to overcome this so that the combo boxes decrease their width automatically to compensate for the Label size increase? Something like anchoring WRT a control instead of a Form.
UPDATE
OK. I think I've found a solution to this one. The Form has a Language property which is used to set language specific properties for a Form. If I change it to Japanese and make changes to Form layout and Control positions then these language specific items are stored in a new .RESX file for each Form. The Satellite assemblies will still be used to provide the localized strings but these RESX files will resize the Form elements accordingly. Is this the right way?
The Form has a Language property which is used to set language specific properties for a Form. If I change it to Japanese and make changes to Form layout and Control positions then these language specific items are stored in a new .RESX file for each Form. The Satellite assemblies will still be used to provide the localized strings but these RESX files will resize the Form elements accordingly.
I don't know anything that can resolve satisfactorily your problem.
There is the property AutoEllipsis=True (with AutoSize=False) that can alleviate the situation.
If set to True this property insert three dot to the right of the label when the text exceed the label dimensions. Positioning the mouse over the label will dispaly a tooltip with the full text.

Highlighting text in a textbox without using RichTextBox control

I have a WPF textbox (not a RichTextBox) and inside this textbox, I want to highlight search results (like in web browsers)
For example if I search for "abc", all occurences of "abc" should be highlighted (for example, with some red background or font)
I want to know if this is possible without using RichTextBox control, or not really?
It's possible but it's much more easy to use a RichTextBox so you may consider to use that instead, moreover you cannot change font size but only color (background and/or foreground) and effects.
First you have to derive your own class from TextBox because you'll override its render method. Now override the OnRender() method, here you'll use the DrawingContext.DrawText() method to draw the text (place everything inside a FormattedText object, primary you'll have to adjust its properties to make it similar to a standard TextBox).
Now what you have is a plain TextBox where in addition you draw your text. From this starting point you can choose to:
Completely override TextBox text drawing: set TextBox.Foreground property to Brushes.Transparent. User will interact with "real" text but he'll see the text your draw. Please note that to make this works you have to mimic exactly how text is drawn (if you change font size, for example, then they'll be unaligned) in the original TextBox.
Add the highlight feature you need keeping the base TextBox text drawing: calculate where the text you want to highlight is and then draw the proper background.
References
This (simplified!) algorithm comes from CodeBox2, it was originally designed to extend a TextBox with some simple editor-like features.
There is no built-in functionality for this. Also, the TextBox only supports a single fontstyle for the entire text.
If the text should be read-only, you could use a flow or fixed document and format the text in Run Elements.

Difference between Textbox and RichTextbox wpf?

Textbox and RichTextbox are look like same.But don't know the difference.Please tell me anyone, When i have to use TextBox and RichTextbox as well in wpf.
See this Microsoft overview of the differences between a TextBox and a RichTextBox.
From above Link:
Both RichTextBox and TextBox allow users to edit text, however, the two controls are used in different scenarios. A RichTextBox is a better choice when it is necessary for the user to edit formatted text, images, tables, or other rich content. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a RichTextBox. A TextBox requires less system resources then a RichTextBox and it is ideal when only plain text needs to be edited (i.e. usage in forms).
A RichTextBox mainly used if you want more control over styling the text color, type, font, alignment ect. So anything you can do in Microsoft Word, you can do with a RichTextBox.
It can be used to save or display .rtf files with ease.
A Textbox is basically used to display or get one line input. You can have a multi-line TextBox which is used mainly to display or get more than one one-liner and keeps you from having to
manage multiple TextBox's. Also keeps your UI a little more tidy.
So basically the main difference is in styling. If you just want something plain and simple, use TextBox. If you want something fancy, eg styles, colors use a RichTextBox.
Have a look at this:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a06ab05a-fbde-47ef-89c5-a7a57f32ffd3
A lot has been said about the differences in the controls' usage scenario.
An important technical difference is that TextBox supports DataBinding, RichTextBox does not, which makes it a bit nasty to use in an MVVM application. If you want a RichTextBox with DataBinding facilities, check out the extended WPF Toolkit on CodePlex.

Resources