WPF中Popup上的textbox无法切换到中文输入法

Wpf画面处理时,遇到个问题,popup上怎么都切换不出输入法,只有QQ输入法勉强能切出来打中文,但是也看不到输入框,原来popup上的textbox无法切换出输入法,是微软的一个bug,微软说4.0会修正该bug,项目是3.5的,最新的4.0试了下确实已经修正该问题,可惜用不到。需要自己写个自定义的popup做处理。可能是popup的弹出性质导致的,大概是popup出现时总是处于Active状态,切换输入法时又必须使输入法处于Active状态,以致无法换成切换。代码前半段连语法不会,转不成vb.net,直接c#编译成dll供日后使用算了。


using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Runtime.InteropServices;
 using System.Windows.Controls.Primitives;
 using System.Windows.Interop;
 using System.Windows.Input;
 using System.Windows;
 namespace HDTWpfControls.vb
 {
     public class HdtPopup : Popup
     {
         [DllImport("user32.dll")]
         static extern IntPtr SetActiveWindow(IntPtr hWnd);
         static void HdtPopup()
         {
             EventManager.RegisterClassHandler(typeof(HdtPopup), Popup.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);
                 }
             }
         }
     }
 }


转自:  http://blog.sina.com.cn/s/blog_90231c3a0100wrob.html

 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值