开发者

Retain focus on a UI element, but click a button on a different dialog. WPF C#

I am developing a touchscreen friendly app that also includes a virtual keyboard. My virtual keyboard is in its own window, a开发者_JS百科llowing it to be moved around. The problem is that when I click on a key on the keyboard the text box on the main application window no longer has focus. The switch from the main application being the active window to the keyboard dialog being the active window means that any field on the main window no longer has focus. How can I get around this?

I tried setting the keyboard window as not focusable. Though this is probably good to set, it did not solve my problem.


You could just return focus to the original window asynchronousely:

public static void BackgroundFocus(this UIElement el)    
{        
    Action a = () => el.Focus();        
    el.Dispatcher.BeginInvoke(DispatcherPriority.Background, a);    
}

But this is not ideal, because the original window caption would flicker when losing focus... Why don't you use Popup instead?


Check out the function SetForegroundWindow() , I have used this long time back some where in my project May be this may help you


Using a Popup, as already suggested, seems like a good solution. As for your custom window, try setting the Window.ShowActivated to false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜