简体   繁体   English

Windows Phone 8.1 MenuFlyout错误?

[英]Windows Phone 8.1 MenuFlyout Bug?

I have an Page AppBar that contains an CommandBar in this command bar I have AppBar Buttons that when on clicked open a MenuFlyout like below: 我在此命令栏中有一个页面AppBar,其中包含CommandBar。我有AppBar按钮,单击这些按钮时,打开如下所示的MenuFlyout:

<AppBarButton Icon="World" Label="Maps" ToolTipService.ToolTip="Map Providers!" IsCompact="True">
                    <AppBarButton.Flyout>
                        <MenuFlyout>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">Unison Maps</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">Google Maps</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">Bing Maps</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">OpenStreetMap</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">OpenCycleMap</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">OCM Transport</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">OCM Landscape</MenuFlyoutItem>
                            <MenuFlyoutItem Click="mapProviderMenuFlyoutItem_Click">MapQuest OSM</MenuFlyoutItem>
                        </MenuFlyout>
                    </AppBarButton.Flyout>
                </AppBarButton>

The first button works great, it shows all menu items in the menu flyout, however the other buttons are stripping out menu items as the MenuFlyout is not large enough to display all results. 第一个按钮效果很好,它显示了菜单弹出菜单中的所有菜单项,但是其他按钮正在剥离菜单项,因为MenuFlyout不够大,无法显示所有结果。

The above code can be added multiple times in the project and results in the same bug. 上面的代码可以在项目中多次添加,并导致相同的错误。

Does anyone have a solution for this? 有人对此有解决方案吗?

EDIT : it appears to be a known bug. 编辑 :这似乎是一个已知的错误。 See this answer for a workaround. 解决方法请参见此答案


I don't think MenuFlyout is designed for use with an AppBarButton . 我不认为MenuFlyout设计用于与AppBarButton一起使用。 It's more suitable as a longpress menu on a ListViewItem . 它更适合作为ListViewItem上的长按菜单。 In any case, I've never seen MenuFlyout used on an AppBarButton in any official Microsoft apps. 无论如何,我从未见过在任何正式的Microsoft应用程序的MenuFlyout使用过AppBarButton Usually they'd use ListPickerFlyout instead. 通常,他们会使用ListPickerFlyout代替。

For example, you could use the following XAML: 例如,您可以使用以下XAML:

<Page
    x:Class="App7.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="World" Label="Maps" ToolTipService.ToolTip="Map Providers!" IsCompact="True">
                <AppBarButton.Flyout>
                    <ListPickerFlyout ItemsSource="{Binding MapProviders}" />
                </AppBarButton.Flyout>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid></Grid>
</Page>

with code behind: 后面有代码:

public sealed partial class MainPage : Page
{
    public List<string> MapProviders { get; private set; }

    public MainPage()
    {
        this.InitializeComponent();
        this.NavigationCacheMode = NavigationCacheMode.Required;

        MapProviders = new List<string>
        {
            "Unison Maps",
            "Google Maps",
            "Bing Maps",
            "OpenStreetMap",
            "OpenCycleMap",
            "OCM Transport",
            "OCM Landscape",
            "MapQuest OSM"
        };
    }
}

to produce a flyout like this (which is scrollable): 产生这样的弹出按钮(可滚动):

在此处输入图片说明

Of course, this is a very simplified example and you could set the ItemsSource by other means. 当然,这是一个非常简化的示例,您可以通过其他方式设置ItemsSource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM