1

我一直在看 Xamarin.Forms Shell。默认情况下,Shell 中可用的浮出控件允许从屏幕左侧滑动或点击工具栏菜单按钮以使浮出控件出现在屏幕左侧。

我还看到了这种情况的变体,其中工具栏和弹出按钮被翻转,因此工具栏按钮和弹出按钮位于屏幕的右侧。

我的问题是 - 我想在屏幕上显示多个弹出窗口。Shell 有效,但如果我使用 Shell(左侧或右侧,但不能同时使用两者),我似乎只能有一个弹出按钮。有没有办法在 Shell 中使用多个弹出窗口?

或者,有没有更好的解决方案使用其他东西?

4

1 回答 1

0

您可以SideMenuViewPageXamarin.CommunityToolkit 包中使用,它已经可用但尚未记录。

您可以在SideMenuViewPage.xaml中找到以下代码的完整示例

样本

<xct:SideMenuView x:Name="SideMenuView">
        <!-- MainView -->
        <StackLayout BackgroundColor="Gold">
              <Label Text="This is the Main view" VerticalOptions="Center" HorizontalOptions="Center"/>
        </StackLayout>

        <!-- LeftMenu -->
        <StackLayout
            xct:SideMenuView.Position="LeftMenu"
            xct:SideMenuView.MenuWidthPercentage=".5"
            xct:SideMenuView.MainViewScaleFactor=".95"
            BackgroundColor="Orange">

              <Label Text="This is the left menu view"/>
        </StackLayout>

        <!-- RightMenu -->
        <StackLayout
            xct:SideMenuView.Position="RightMenu"
            xct:SideMenuView.MenuWidthPercentage=".3"
            xct:SideMenuView.MenuGestureEnabled="False"
            BackgroundColor="LightGreen">

              <Label Text="This is the Right menu view"/>
        </StackLayout>

</xct:SideMenuView>

可用属性

财产 描述
MenuWidthPercentage 设置菜单相对于其父级的宽度百分比。
MainViewScaleFactor 设置打开侧边菜单(左侧或右侧)时 MainView 将缩放到的缩放百分比。
Position 指定位置是右还是左还是主视图,如果没有指定,它将被视为主视图。
MenuGestureEnabled 启用/禁用侧滑手势选项以打开/关闭菜单/视图。

打开/关闭侧面菜单视图(弹出)

从代码

通过滑动手势或通过设置您在 xaml 中定义的属性State来打开左右菜单/视图:SideMenuView

SideMenuView.State = SideMenuState.MainViewShown;    //show main view and close both left and right menu view
SideMenuView.State = SideMenuState.RightMenuShown;   //Open right menu view
SideMenuView.State = SideMenuState.LeftMenuShown;    //Open left menu view

来自 xml

默认情况下,左右菜单是关闭的(State属性的默认值为MainViewShown),如果您希望最初打开一个菜单,请在您的 xaml 中更改它的值:

<xct:SideMenuView x:Name="SideMenuView" State="LeftMenuShown">

一种混合方法是绑定State到一个属性并根据您的逻辑在您的代码中更改它。

笔记

目前它仅支持 iOS 和 Android(不支持 uwp)。

于 2021-03-25T23:17:14.230 回答