我有以下 XAML
<StackPanel MouseEnter="StackPanel_MouseEnter" Height="130" Background="Blue">
<Grid MouseEnter="Grid_MouseEnter" Height="60" Background="Red" >
<Button MouseEnter="Button_MouseEnter" Height="20"/>
</Grid>
</StackPanel>
在后面的代码中我正在这样做
private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
{
}
private void Grid_MouseEnter(object sender, MouseEventArgs e)
{
e.Handled = true;
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
e.Handled = true;
}
现在,即使我将鼠标移到Button
set上,也会分别调用和e.Handled = true
的事件。为什么?我应该怎么做才能阻止路由事件冒泡?Grid
StackPanel