以下に示す .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");
}
}