2014-09-22 159 views
1

我有一个包含一个命令栏这个命令栏的页面AppBar我有AppBar按钮,点击打开一个MenuFlyout像下面的时候:Windows Phone 8.1 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> 

的第一个按钮的伟大工程,它显示菜单中的所有菜单项弹出,但其他按钮正在剥离菜单项,因为MenuFlyout不够大,无法显示所有结果。

上述代码可以在项目中多次添加,并导致相同的错误。

有没有人有解决方案?

回答

0

编辑:它似乎是一个已知的错误。有关解决方法,请参阅this answer


我不认为MenuFlyout是专为与AppBarButton使用。它更适合作为ListViewItem的长按菜单。无论如何,我从来没有在任何官方的微软应用程序中看到AppBarButton上使用MenuFlyout。通常他们会使用ListPickerFlyout

例如,可以使用下面的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> 

与后面的代码:

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" 
     }; 
    } 
} 

,以产生这样的弹出按钮(其是可滚动):

enter image description here

当然,这是一个非常简单的例子,您可以设置ItemsSource通过其他方式。

+0

微软将它添加上下文菜单到那里的应用程序按钮。 http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150602.aspx。一个Windows商店应用程序的行为正确的Windows Phone 8.1应用程序没有。这对我来说似乎是一个错误。 – Xela 2014-09-22 20:45:14

+0

您目前的方法是我之前使用的方法,但我希望使我的Windows Phone 8.1应用程序更通用,并与平板电脑相对应地共享更多代码。 – Xela 2014-09-22 20:49:09

+0

如果你想分享代码,你可以尝试PopupMenu类。它也适合ContextMenu,但它不是可定制的。 http://compiledexperience.com/blog/posts/positioning-popup-menus-in-windows-8-metro/ - 这是示例(也适用于通用应用程序)。 – 2014-09-23 16:17:46