WindowsFormsHost导致System.Windows.Forms.Button.Click事件无法触发

时间:2012-09-25 13:31:21

标签: wpf button windowsformshost

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

要托管winform控件,我正在使用WindowsFormsHost,而且似乎正在发生的事情是输入按键不会导致在winforms按钮上触发Button.Click事件(但是,使用鼠标和空格键单击仍然有效)。

您可以通过执行以下操作重现此行为:

<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添加一个事件处理程序来调用Button.PerformClick如果按下了enter并且按钮被聚焦了,但我觉得必须有一些我忽略的东西为什么输入不会导致按钮单击发生。

0 个答案:

没有答案
相关问题