重现我的案例 (.net 4.0)
你的项目准备好了,
你会看到你不能在 Window1 中将焦点设置在文本框上,因为 MainWindow Texbox(在 winformshost 中会窃取你对你的应用程序激活的关注)
任何的想法?
主窗口.xaml
<Window x:Class="WinFormsHostFocusProblem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WinFormsHostFocusProblem"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="MainWindow" Height="350" Width="525">
<Grid>
<my:WindowsFormsHost Focusable="False" >
<local:UserControl1>
</local:UserControl1>
</my:WindowsFormsHost>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
主窗口.xaml.cs
namespace WinFormsHostFocusProblem
{
public partial class MainWindow : Window
{ …Run Code Online (Sandbox Code Playgroud)