下拉的Textbox无法输入中文应该是wpf的bug,以下是解决方案
public class MyDropDown : C1DropDown
{
[DllImport("user32.dll")]
static extern IntPtr SetActiveWindow(IntPtr hWnd);
static MyDropDown()
{
EventManager.RegisterClassHandler(typeof(MyDropDown), C1DropDown.PreviewGotKeyboardFocusEvent,
new KeyboardFocusChangedEventHandler(OnPreviewGotKeyboardFocus), true);
}
private static void OnPreviewGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
{
var textBox = e.NewFocus as TextBoxBase;
if (textBox != null)
{
var hwndSource = PresentationSource.FromVisual(textBox) as HwndSource;
if (hwndSource != null)
{
SetActiveWindow(hwndSource.Handle);
}
}
}
} |