使用下面进一步列出的 .net 4.0 代码会发生以下行为:
单击文本框使其获得焦点,然后单击按钮:
- 就代码而言,调用了 lostfocus 处理程序,但没有调用 buttonclick 处理程序
- 注释掉 MessageBox.Show("handlelostfocus") 然后单击处理程序被调用
- 在 handlelostfocus 中设置断点并命中断点,但未调用单击处理程序
这些错误或行为是设计的 - 如果稍后,是否有任何进一步的解释?
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="216,194,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="197,108,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
textBox1.LostFocus += new RoutedEventHandler(handlelostfocus);
}
private void handlelostfocus(object sender, RoutedEventArgs e)
{
MessageBox.Show("handlelostfocus");
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("click");
}
}