当鼠标指针进入MenuFlyoutItem时会触发PointerEntered,但是当它进入MenuFlyoutSubItem时则不会触发。当鼠标指针进入MenuflyoutSubItem元素时会触发什么事件?我想在鼠标指针进入时捕获事件处理程序中的MenuflyoutSubItem元素的text属性。 (我不能依赖tapped事件的原因是因为即使只是悬停在MenuFlyoutSubItem上也会打开其包含的菜单项。)以下是代码:
public DynamicMenuTestPage()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
MenuFlyoutSubItem myItem = new MenuFlyoutSubItem();
myItem.Text = "Item" + i;
myItem.PointerEntered += MyItem_PointerEntered;
MyMenu.Items.Add(myItem);
for (int j = 0; j < 4; j++)
{
MenuFlyoutItem mySubItem = new MenuFlyoutItem();
mySubItem.Text = "SubItem" + j;
mySubItem.PointerEntered += mySubItem_PointerEntered;
myItem.Items.Add(mySubItem);
}
}
}
private void MyItem_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
// This does not work. It is not triggered when the mouse pointer enters the menu flyout subitem.
MenuFlyoutSubItem test = sender as MenuFlyoutSubItem;
var menuFlyoutSubItemText = test.Text;
}
private void mySubItem_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{ //This works. It is triggered when the mouse pointer enters the menu flyout item.
MenuFlyoutItem test = sender as MenuFlyoutItem;
var menuFlyoutItemText = test.Text;
}
这是菜单的屏幕截图。当我将鼠标悬停在Item0上时,以红色圈出,子菜单打开。什么事件将使我能够捕获文本,&#34; Item0&#34;?