次の方法で共有


Developing Arabic WPF applications – Part 3

I talked before about changing the input language in a textbox in Windows Forms but what about WPF? In WPF, you should use the InputLanguageManager class. You can use it in either the code or in the XAML markup. I wrote a sample to demo an application with default language set to Arabic(Egypt).

<Window x:Class="WpfApplication1.Window1"

   xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

   InputLanguageManager.InputLanguage="ar-EG"

   Title="Input Language Change" Height="300" Width="300">

    <Grid>

        <StackPanel Name="stackPanel1">

        <TextBox InputLanguageManager.InputLanguage="en-US" InputLanguageManager.RestoreInputLanguage="True"  Name="textBox1" Margin="10,4,10,10"/>

        <TextBox Name="textBox2" Margin="10,4,10,10" />

        <TextBox Name="textBox3" Margin="10,4,10,10"/>

            </StackPanel>

    </Grid>

</Window>

TextBox2 is set to English input by default while the rest of the textboxes default to Arabic. Notice to return back to the default input you need to set InputLanguageManager.RestoreInputLanguage="True" , since the default is “False”.

Notice, you need to make sure that the keyboard already exists in your OS.

Comments