1

我对 WPF DataGrid 有一个可怕的问题!我在TextBox里面放了一个DataGridColumnHeader,并改变了KeyBoardLanguageon TextBox_GotFocus。这是我的风格DataGridColumnHeader

<Style x:Key="DataGridSelectorColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}" >
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <TextBox  xamlservices:GotFocusBehavior.GotFocus="{Binding TextBoxGotFocusCommand}"
                          xamlservices:GotFocusBehavior.GotFocusParameter="{Binding RelativeSource={RelativeSource Mode=Self}}"/>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

和:

  public ICommand TextBoxGotFocusCommand
    {
        get { return new RelayCommand<TextBox>(OnTextBoxGotFocus); }
    }
  TextBox txtSearch;
  private void OnTextBoxGotFocus(TextBox sender)
  {
     txtSearch = sender;
     if (...)
     {
       CultureInfo lanq = new CultureInfo("en-us", false);
       InputLanguageManager.SetInputLanguage(txtSearch, lanq);
     }
  }

问题是当我点击时语言会改变Textbox,点击其他地方并返回TextBox!它不会在第一次点击时改变语言。任何想法将不胜感激。

4

0 回答 0