Appbar背后的弹出窗口

时间:2014-10-31 15:09:02

标签: c# winrt-xaml win-universal-app

如果您希望自己的应用扩展到全屏(包括状态栏和appbar),则需要执行以下操作:

var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);

然后,如果您想在应用栏或应用中的任何位置设置弹出按钮,它们将显示在应用栏后面:

    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Preview" Label="Preview">
                <AppBarButton.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Fit width" />
                        <MenuFlyoutItem Text="Fit height" />
                        <MenuFlyoutItem Text="Fit page" />
                    </MenuFlyout>
                </AppBarButton.Flyout>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>

结果:

http://i.stack.imgur.com/oWAj9.png

列表视图中项目的弹出窗口相同。它们将显示在appbar后面:

enter image description here

如何在应用栏顶部显示弹出按钮?

1 个答案:

答案 0 :(得分:5)

我似乎无法解决我的问题(或者可以提供帮助的人)。所以我这样做,如果它可以帮助某人:

<Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Preview" Label="Preview">
                <AppBarButton.Flyout>
                    <MenuFlyout Opened="MenuFlyout_Opened" Closed="MenuFlyout_Closed">
                        <MenuFlyoutItem Text="Fit width" />
                        <MenuFlyoutItem Text="Fit height" />
                        <MenuFlyoutItem Text="Fit page" />
                    </MenuFlyout>
                </AppBarButton.Flyout>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>

private void MenuFlyout_Opened(object sender, object e)
{
  BottomAppBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}

private void MenuFlyout_Closed(object sender, object e)
{
  BottomAppBar.Visibility = Windows.UI.Xaml.Visibility.Visible;
}

现在我的弹出窗口显示完全,因为没有更多的appbar。对于mvvm列表视图项,我在行为操作中完成了它:

<DataTemplate x:Key="MvvmItemTemplate">
        <Grid>

            <i:Interaction.Behaviors>
                <icore:EventTriggerBehavior EventName="Holding">
                    <local:OpenFlyoutAction />
                </icore:EventTriggerBehavior>
            </i:Interaction.Behaviors>

            <FlyoutBase.AttachedFlyout>
                <MenuFlyout>
                    <MenuFlyoutItem ..... Command="{Binding MarkRead}" />
                    <MenuFlyoutItem ..... Command="{Binding MarkUnread}" />
                    <MenuFlyoutItem ..... Command="{Binding PinToStart}" />
                </MenuFlyout>
            </FlyoutBase.AttachedFlyout>
        </Grid>
    </DataTemplate>




public class OpenFlyoutAction : DependencyObject, IAction
    {
        public object Execute(object sender, object parameter)
        {
            // Show menu
            FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);

            // sometimes the appbar is stuck behind the appbar, so hide the appbar
            (sender as FrameworkElement).GetFirstAncestorOfType<Page>().BottomAppBar.Visibility = Visibility.Collapsed;

            // show the appbar again when flyout is closed
            var flyout = FlyoutBase.GetAttachedFlyout((FrameworkElement)sender);
            EventHandler<object> showBar = null;
            showBar = delegate (object s, object e)
            {
                (sender as FrameworkElement).GetFirstAncestorOfType<Page>().BottomAppBar.Visibility = Visibility.Visible;
                // unsubscribe handler:
                flyout.Closed -= showBar;
            };
            flyout.Closed += showBar;

            return null;
        }
    }