How do I get RTL text in FlowDocument right-aligned?
Hello,
I have a FlowDocument with some figure and table and paragraphs in it. I use it usually to display LTR text and that's okay. However, If I want to display Hebrew for example, the paragraphs are still left aligned.
Is there a way how to get it aligned properly? Unfortunately I don't have CultureInfo information about the text, just the text; but I'd like it to be aligned automatically anyway, if possible.
Any ideas welcomed,
thanks, Jan.
Hi,
thank you for reply. Hmm, that's what I was afraid of. So..not quite a WPF question, but any way, how to detect if text is RTL without checking for specific set of languages? Like Char.IsRtl or something like that....
Jan
Hello, are you sure? Actually when you set FlowDirection to RightToLeft, and set TextAlignment to Left (the default value), the result will appear to be right aligned. This should be done automatically, and is the result I got. Maybe you’ve manually set TextAlignment to Right? If so, in a RightToLeft environment, your text will appear to be left aligned.
Hi.
Well first this is the very unfortunate confusion caused be using Left and Right names instead of good old Near and Far, as I pointed at Near, Far, Left, Right (WPF) and NearToFar, FarToNear, LeftToRight, RightToLeft (WPF) feedback at Connect (two months ago, still without any answer!).
And concerning my problem. I agree that with setting the FlowDirection to RightToLeft, the left-aligned paragraphs become right-aligned. However, this is not what I'm asking for. Originally I didn't want to set FlowDirection at all, expecting the paragraphs to get their defaults based on the content. Well I may or might not agree whether this would be good behaviour, it seems it simply does not work this way.
So I decided I will manually set the FlowDirection to RightToLeft to get the effect. But how should I detect, if the text is naturally RTL? I can get the character and test whether it is Arabic, Hebrew and so on, but I'll likely miss some case, so I'm looking for more general way of doing that.
Jan