开发者

Can't change input language of RichTextBox (WPF)

开发者 https://www.devze.com 2023-01-16 13:10 出处:网络
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.

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 except开发者_开发百科ions 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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消