应用程序菜单弹出

应用程序菜单弹出

本文介绍了菜单项内的 Windows 10 UWP 应用程序菜单弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在菜单弹出式菜单项中设置菜单弹出式菜单?

Is it possible to have a menu flyout inside a menu flyout item?

        <AppBarButton x:Name="Button" Icon="Add" Label="Create List">
            <AppBarButton.Flyout>
                <MenuFlyout>
                    <MenuFlyoutItem Text="b1">
                        <FlyoutBase.AttachedFlyout>
                            <MenuFlyout x:Name="ItemsMenu" Placement="Left">
                                <MenuFlyoutItem Text="test1"/>
                                <MenuFlyoutItem Text="test2"/>
                            </MenuFlyout>
                        </FlyoutBase.AttachedFlyout>
                    </MenuFlyoutItem>
                    <MenuFlyoutItem Text="b2" />
                    <MenuFlyoutItem Text="b3" />
                    <MenuFlyoutItem Text="b4" />
                    <MenuFlyoutItem Text="b5" />
                </MenuFlyout>
            </AppBarButton.Flyout>
        </AppBarButton>

单击该项目只会使菜单消失.我尝试在鼠标指针进入时调用 ItemsMenu.ShowAt() 但是当我将鼠标悬停在它上面时它只会使菜单消失.谁有想法?

Clicking on the item just makes the menu disappear. I tried calling ItemsMenu.ShowAt() on mouse pointer enter but it just makes the menu disappear when I hover over it. Any one have any ideas?

推荐答案

我试过你的代码,但无法运行,所以想了个迂回的方法来解决,希望能给你一些启发:

I have tried your code but can't make it work , so I figure out a roundabout method to solve it, I hope this will provide some inspirations for you:

<Page.Resources>
    <CollectionViewSource x:Key="cvs" x:Name="cvs" IsSourceGrouped="True"/>
    <Flyout x:Key="DeclarativeAttachedFlyout">
        <StackPanel>
            <Button Content="b1">
                <Button.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="t1"></MenuFlyoutItem>
                        <MenuFlyoutItem Text="t2"></MenuFlyoutItem>
                        <MenuFlyoutItem Text="t3"></MenuFlyoutItem>
                        <MenuFlyoutItem Text="t4"></MenuFlyoutItem>
                    </MenuFlyout>
                </Button.Flyout>
            </Button>
            <Button Content="b2"></Button>
            <Button Content="b3"></Button>
            <Button Content="b4"></Button>
            <Button Content="b5"></Button>
        </StackPanel>
    </Flyout>

 <MenuFlyout x:Key="DeclarativeAttachedFlyout2">
        <MenuFlyoutItem Text="b1" ></MenuFlyoutItem>
        <MenuFlyoutItem Text="b2" ></MenuFlyoutItem>
        <MenuFlyoutItem Text="b3" ></MenuFlyoutItem>
        <MenuFlyoutItem Text="b4" ></MenuFlyoutItem>
        <MenuFlyoutItem Text="b5" ></MenuFlyoutItem>
        <MenuFlyoutSubItem Text="s1">
            <MenuFlyoutItem Text="b6"></MenuFlyoutItem>
        </MenuFlyoutSubItem>
    </MenuFlyout>
</Page.Resources>
<AppBarButton x:Name="button" Icon="Add" Label="Create List" Flyout="{StaticResource DeclarativeAttachedFlyout}"> </AppBarButton>
<AppBarButton x:Name="button" Icon="Add" Label="Create List" Flyout="{StaticResource DeclarativeAttachedFlyout2}"> </AppBarButton>

这里有关于flyout的详细解释,你可以点击这个

Here is a detailed explain about flyout , you may click this

这篇关于菜单项内的 Windows 10 UWP 应用程序菜单弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 23:54