gpt4 book ai didi

c# - MouseEnter 事件的奇怪行为

转载 作者:太空狗 更新时间:2023-10-29 23:53:30 25 4
gpt4 key购买 nike

我正在开发 Windows Phone 8 XAML 应用程序。

我为 XAML 页面中的多个对象定义了 MouseEnter 事件。 (例如两个矩形)。触发这些对象的 MouseEnter 事件后,我按下同一页面上的一个按钮。按钮按下不仅会触发其自身的点击事件。它还会触发最后输入的 Rectangle 的 MouseEnter 事件。

这个问题可以通过一个只有两个矩形和一个按钮的新项目重现。这种行为并不总是出现,但可以在几次触发 Rectangles 的 MouseEnter 事件后观察到。

我的 XAML 对象如下。

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100"
Margin="102,306,0,0" Stroke="Black"
VerticalAlignment="Top" Width="100"
MouseEnter="Rectangle_MouseEnter"/>

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100"
Margin="314,306,0,0" Stroke="Black"
VerticalAlignment="Top" Width="100"
MouseEnter="Rectangle_MouseEnter"/>

<Button Content="Button" HorizontalAlignment="Left"
Margin="256,481,0,0" VerticalAlignment="Top" Click="Button_Click"/>

后面的代码看起来像这样。

private void Rectangle_MouseEnter(object sender, 
System.Windows.Input.MouseEventArgs e)
{
Debug.WriteLine("Rectangle_MouseEnter");
}

private void Button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Button_Click");
}

最佳答案

如果我记得,在 Windows pone 和 Windows 8 应用程序中,最好使用点击事件而不是鼠标事件。这可能是问题所在。查看此链接:

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.tapped.aspx

关于c# - MouseEnter 事件的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com