如何prevent窃取焦点一个新的WPF的形​​式? [英] How to prevent a new WPF form from stealing focus?

查看:113
本文介绍了如何prevent窃取焦点一个新的WPF的形​​式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的 MSN 风格的程序,将发送和检索使用的WCF 。主窗体包含一个文本框中键入消息发送。在后台的应用程序轮询服务器每隔几秒钟是否有新邮件。当接收到一个新的消息的新窗口被打开以显示它。这必须使用Dispatcher类的UI线程上完成的。

I have written a simple MSN-style program that will send and retrieve messages using WCF. The main form contains a Textbox to type in the message to be sent. In the background the application polls the server every few seconds for new messages. When a new message is received a new window is opened to display it. This has to be done on the UI thread using the Dispatcher class.

的问题是,该新窗口被显示时,焦点转移远离文本框,以便输入被中断。这是很烦人!在 MSN Messenger的的,可以继续输入自己的信息,同时接收之一。它是如何做?

The problem is that when the new window is shown, the focus shifts away from the TextBox, so that typing is interrupted. This is very annoying! In MSN Messenger it is possible to continue typing your own message while receiving one. How is it done?

作为一种解决方法我推迟弹出新邮件,而文本框具有焦点,但应该有一个更好的办法!

As a workaround I postpone the popup with the new message while the TextBox has focus, but there should be a better way!

推荐答案

答案很简单:因为.NET 3.5 SP1的WPF的形​​式有一个 ShowActivated 属性。设置此为假,任何形式打上不会偷没有重点没了!

The answer is simple: Since .NET 3.5 SP1 WPF forms have a ShowActivated property. Set this to false and any form thus marked won't steal no focus no more!

这篇关于如何prevent窃取焦点一个新的WPF的形​​式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆