views:

50

answers:

0

Hi,

I'm trying to add to my RichEditBox'd tool bar a button to switch languages, like in MS Word. I can't seems to make this work. When I use the keyboard (alt+shift) I can switch between Hebrew and English without any problem, but the code below (and many other options I tried) is not working. The last commented line didn't work either. Just to be clear, there are no exceptions and nothing fails. The selected text in the RichTextBox changes the flow direction to RTL - but the language remains English. Any idea?

Thanks, Yariv

Edited: I have found a similar issue HERE and it seems like the author have found a solution to his problem, but I don't understand the solution...

    private void OnChangeLanguage(object sender, RoutedEventArgs e)
    {
        RichTextBox textBox = GetTemplateChild("innerRTB") as RichTextBox;
        if (textBox == null)
            return;

        string langString = CultureInfo.CurrentCulture.IetfLanguageTag;
        XmlLanguage newXmlLanguage = XmlLanguage.GetLanguage(langString);

        TextRange selectionRange = new TextRange(textBox.Selection.Start, textBox.Selection.End);
        selectionRange.ApplyPropertyValue(FlowDocument.FlowDirectionProperty, FlowDirection.RightToLeft);
        selectionRange.ApplyPropertyValue(FlowDocument.LanguageProperty, "he-il");
        // selectionRange.ApplyPropertyValue(FlowDocument.LanguageProperty, newXmlLanguage);
    }