我有一個按鈕和邊框的畫布:即使鼠標點放在元素上,爲什麼MouseLeave事件被觸發?
<Grid>
<Canvas Name="canvas1" >
<Button Name="button1" Visibility="Hidden" />
<Border BorderBrush="Red" BorderThickness="6" Name="border1" />
</Canvas>
</Grid>
現在,我想要的是在border1的了mouseenter,button1的應該是可見的和邊界本身應該被隱藏。反之亦然。所以編寫了兩個事件的處理程序:
void border1_MouseLeave(object sender, MouseEventArgs e)
{
border1.Visibility = Visibility.Visible;
button1.Visibility = Visibility.Hidden;
}
void border1_MouseEnter(object sender, MouseEventArgs e)
{
border1.Visibility = Visibility.Hidden;
button1.Visibility = Visibility.Visible;
}
問題是即使將鼠標指針放在邊框上,MouseLeave也會觸發。我在這裏做錯了什麼?