Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf WindowsFormsHost导致System.Windows.Forms.Button.Click事件不触发_Wpf_Button_Windowsformshost - Fatal编程技术网

Wpf WindowsFormsHost导致System.Windows.Forms.Button.Click事件不触发

Wpf WindowsFormsHost导致System.Windows.Forms.Button.Click事件不触发,wpf,button,windowsformshost,Wpf,Button,Windowsformshost,我正在将windows窗体应用程序转换为WPF,并在转换的第一部分重新使用一些winform控件 要托管winform控件,我使用的是WindowsFormsHost,似乎发生的情况是enter键没有导致按钮。单击winforms按钮上要触发的事件(但是,使用鼠标和空格键单击仍然有效) 您可以通过执行以下操作来复制此行为: <Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com

我正在将windows窗体应用程序转换为WPF,并在转换的第一部分重新使用一些winform控件

要托管winform控件,我使用的是WindowsFormsHost,似乎发生的情况是enter键没有导致按钮。单击winforms按钮上要触发的事件(但是,使用鼠标和空格键单击仍然有效)

您可以通过执行以下操作来复制此行为:

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"  
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <WindowsFormsHost>
        <wf:Button Text="Hello" Click="Button_Click_1"  />
    </WindowsFormsHost>
</Grid>

我正在考虑向WindowsFormsHost call按钮添加一个事件处理程序。如果按下enter键且某个按钮处于焦点状态,则执行单击,但我觉得一定有什么我忽略了的,为什么enter键不会导致按钮单击