gpt4 book ai didi

c# - Appbar 后面的弹出窗口

转载 作者:行者123 更新时间:2023-11-30 14:54:56 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com