c# - Appbar 后面的弹出窗口

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

当你想让你的应用扩展到全屏时(包括状态栏和应用栏),你必须这样做:

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

与 ListView 中项目的弹出窗口相同。它们将显示在应用栏后面:

enter image description here

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

最佳答案

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

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

现在我的弹出窗口完全显示了,因为不再有应用栏。对于 mvvm ListView 项,我是在行为操作中完成的:

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

关于c# - Appbar 后面的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26677814/

相关文章:

c# - AutoSuggestBox 显示属性名称而不是值

c# - 当指针指向项目时如何在gridview中指定项目的样式

c# - 枚举分配看起来不同

c# - 在调用的方法中抛出异常时,如何使用 MethodInfo.Invoke 获取作为引用传递的参数值

c# - 如何在 asp.net web api 中启用 cors 选项。?

c# - 如何在 Windows 8 Metro 应用程序中有用户提示对话框?

javascript - 在winjs中通过后台传输上传之前调整图像大小

c# - Windows 10(现代)通用应用程序平台(UWP)消息框

c# - UWP 项目可以包含没有打包项目的桌面 exe 吗?

c# - 如何部署 "Release"版本的 ASP.NET MVC5 应用程序