我在WPF中有一个带有ComboBox和Button的窗口。
如果在组合框上打开下拉菜单,我单击按钮,然后关闭下拉菜单,但忽略按钮上的单击事件。我必须再次点击才能开火。如何解决这个问题,以便我可以点击打开下拉菜单的按钮?
<ComboBox x:Name="cbName" HorizontalAlignment="Left" Margin="53,75,0,0" VerticalAlignment="Top" Width="120" IsEditable="True" StaysOpenOnEdit="True" GotFocus="cbName_GotFocus"/>
<Button x:Name="btSearch" Content="Search" HorizontalAlignment="Left" Margin="213,75,0,0" VerticalAlignment="Top" Width="75" Click="btSearch_Click" />
private void btSearch_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello");
}
private void cbName_GotFocus(object sender, RoutedEventArgs e)
{
cbName.IsDropDownOpen = true;
}
感谢。