在UWP中无效的弹出按钮内单击appbar按钮的事件

时间:2016-05-26 08:14:19

标签: xaml windows-10 uwp windows-10-universal uwp-xaml

我有一个命令栏,在其中一个appbar按钮上我附加了一个正确显示的弹出按钮。这个弹出窗口再次有一个带有appbar按钮的命令栏。问题是我想在其中一个按钮上再次打开弹出按钮,但这不起作用。请帮忙!

    <Page.Resources>
    <Flyout x:Key="SetBookmarkFlyout">
        <Grid Width="250" Height="250">
            <TextBlock Grid.Row="0">Name</TextBlock>
            <TextBox Grid.Row="1" x:Name="BookmarkName"></TextBox>
            <TextBlock Grid.Row="2">Create in</TextBlock>
            <ComboBox Grid.Row="3"></ComboBox>
        </Grid>
    </Flyout>
    <Flyout x:Key="SubMenuFlyout">
        <CommandBar Background="{ThemeResource     ApplicationPageBackgroundThemeBrush}" Height="250" >
            <AppBarButton Icon="Bookmarks" ToolTipService.ToolTip="Open Bookmarks"></AppBarButton>
            <AppBarButton x:Name="SetBookmark" Icon="Favorite" ToolTipService.ToolTip="Set Bookmark" Click="SetBookmark_Click" FlyoutBase.AttachedFlyout="{StaticResource SetBookmarkFlyout}" ></AppBarButton>
            <AppBarButton Icon="Page" ToolTipService.ToolTip="Recent Files"></AppBarButton>
        </CommandBar>
    </Flyout>
  </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="0,0,0,-10" >

    <CommandBar x:Name="Commandbar" Height="70" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <AppBarButton Icon="Back" Label="" ToolTipService.ToolTip="Back" ></AppBarButton>
        <AppBarButton Icon="Forward" Label="" ToolTipService.ToolTip="Forward" ></AppBarButton>
        <AppBarButton x:Name="SpaceAppBtn"></AppBarButton>

        <AppBarButton Icon="Add" Label="" ToolTipService.ToolTip="Add Tab"></AppBarButton>
        <AppBarButton Icon="Favorite" Label="" ToolTipService.ToolTip="Favorites (Set Bookmark,open Bookmarks, and see recent files)" Click="AppBarButton_Click" FlyoutBase.AttachedFlyout="{StaticResource SubMenuFlyout}">
        </AppBarButton>
        <AppBarButton Icon="Find" Label="" ToolTipService.ToolTip="Search"></AppBarButton>


    </CommandBar>
    </Grid>

1 个答案:

答案 0 :(得分:2)

我已将Flyout直接添加到我的示例中的Button进行测试。

<AppBarButton x:Name="FavoriteButton" Icon="Favorite" Label="" ToolTipService.ToolTip="Favorites (Set Bookmark,open Bookmarks, and see recent files)" 
                 Click="AppBarButton_Click">
        <AppBarButton.Flyout>
            <Flyout>
               <CommandBar Background="{ThemeResource     ApplicationPageBackgroundThemeBrush}" Height="250" >
                   <AppBarButton Icon="Bookmarks" ToolTipService.ToolTip="Open Bookmarks"></AppBarButton>
                    <AppBarButton x:Name="SetBookmark" Icon="Favorite" ToolTipService.ToolTip="Set Bookmark"
                      Click="SetBookmark_Cick">                                
                    </AppBarButton>
                    <AppBarButton Icon="Page" ToolTipService.ToolTip="Recent Files"></AppBarButton>
                    </CommandBar>
            </Flyout>
        </AppBarButton.Flyout>
    </AppBarButton>

使用Popup而不是第二个Flyout。 在CommandBar添加

之后
<CommandBar>...
</CommandBar>
<Popup x:Name="SetBookmarkPopup" HorizontalOffset="200" VerticalOffset="200">
    <Grid Width="250" Height="250">
        <TextBlock Grid.Row="0">Name</TextBlock>
        <TextBox Grid.Row="1" x:Name="BookmarkName"></TextBox>
        <TextBlock Grid.Row="2">Create in</TextBlock>
        <ComboBox Grid.Row="3"></ComboBox>
     </Grid>
</Popup>

并从您的AppBarButton_Click活动

致电
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
     FavoriteButton.Flyout.ShowAt(FavoriteButton);
}  

最后打开Popup

private void SetBookmark_Cick(object sender, RoutedEventArgs e)
{
    SetBookmarkPopup.IsOpen = true;
}

希望有所帮助