wpf怎么在textbox上设置输入法

  • 原创
  • |
  • 浏览: 1387
  • |
  • 更新:

今天小编和大家分享wpf怎么在textbox上设置输入法经验,希望对大家有所帮助。

方法/步骤

  1. 2

    方法如下,此方法不会限制只能输入英文,只是设定初次获得控制项焦点的输入法。

  2. 3

    Style的写法:

    <Setter Property="InputMethod.InputScope">

    <Setter.Value>

    <InputScope>

    <InputScope.Names>

    <InputScopeName NameValue="AlphanumericHalfWidth"></InputScopeName>

    </InputScope.Names>

    </InputScope>

    </Setter.Value>

    </Setter>

  3. 4

    <TextBox.InputScope>

    <InputScope>

    <InputScope.Names>

    <InputScopeName NameValue="AlphanumericHalfWidth"/>

    </InputScope.Names>

    </InputScope>

    </TextBox.InputScope>

  4. 5

    如果是DataGrid要放在Datagrid.Cellstyle

    Code的写法:

    InputScope scope = new InputScope();

    InputScopeName name = new InputScopeName();

    name.NameValue = InputScopeNameValue.AlphanumericHalfWidth;

    scope.Names.Add(name);

    TextBox txt = d as TextBox;

    txt.InputScope = scope;

    END