简体   繁体   English

Xamarin.Forms TabbedPage中的下拉菜单

[英]Dropdown menu in Xamarin.Forms TabbedPage

I have a tabbedpage design like so, 我有这样的选项卡式设计, 标签页

The tabbedpage is already setup, but I can't figure out anyway to achieve the dropdown menu and add an extra button (the filter button in the Image) to the tabbar. 该选项卡式页面已经设置好了,但是无论如何我还是想不起来要使用下拉菜单并在选项卡栏中添加一个额外的按钮(图像中的过滤器按钮)。 A custom renderer for the tabbedpage might work but I'd prefer that as a last resort, please help me out. 标签页的自定义渲染器可能可以工作,但作为最后的解决方法,我希望您帮忙。

It can be done with an AbsoluteLayout and some height calculating. 可以使用AbsoluteLayout和一些高度计算来完成。 No custom renderer needed. 无需自定义渲染器。

Put everything in your TabbedPage.Content in an AbsoluteLayout and then to StackLayout (or other Layout you are using). 将所有内容放入AbsoluteLayout中的TabbedPage.Content中,然后StackLayoutStackLayout (或您正在使用的其他Layout )中。 Then add a Frame (i'm using Frame , but you can use other View ). 然后添加一个Frame (我正在使用Frame ,但是您可以使用其他View )。

<AbsoluteLayout x:Name="absoluteLayout">
     <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
         //other layouts and elements
     </StackLayout>
     <Frame AbsoluteLayout.LayoutFlags="WidthProportional" AbsoluteLayout.LayoutBounds="0,0,1,A" IsVisible="False">
         //your checkboxes and labels
     </Frame>
</AbsoluteLayout>

In the Frame property AbsoluteLayout.LayoutBounds="0,0,1,A" I wrote A, but you have to write a number there: 在Frame属性AbsoluteLayout.LayoutBounds="0,0,1,A"我写了A,但是您必须在其中写一个数字:

  • A = the height of your DropDown Menu A =下拉菜单的高度

If you don't know the height at the initializing of the XAML, you can set it in code too: 如果您不知道XAML初始化时的高度,也可以在代码中进行设置:

AbsoluteLayout.SetLayoutBounds(frame, new Rectangle(0, 0, 1, height)); // X,Y,Width,Height

Explanation and more about Flags is explained here . 在这里解释和解释Flags。 It's quite easy to understand, but if you have trouble, this video helped me. 这很容易理解,但是如果遇到问题, 该视频对我有所帮助。

Now is your DropDown ready. 现在,您的DropDown就绪了。 When you want it to show, just set the visibility. 想要显示时,只需设置可见性即可。

frame.IsVisisble = true;

Tip-1 : You can even animate it to go up and down with using Animations. 提示1 :您甚至可以使用“动画”来对其进行动画处理。 For example, this peace of code will do it. 例如, 代码的这种和平将做到这一点。

Tip-2 : If you add a GestureRecognizers to your StackLayout , the user can click around the DropDown and it will hide. 提示2 :如果将GestureRecognizers添加到StackLayout ,则用户可以在DropDown周围单击,它将隐藏。

XAML: XAML:

<StackLayout.GestureRecognizers>
     <TapGestureRecognizer Tapped="StackLayout_Tapped"/>
</StackLayout.GestureRecognizers>

CODE: 码:

if (frame.IsVisisble)
{
    frame.IsVisisble = false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM