简体   繁体   English

Xamarin 选项卡式页面内容除选项卡外

[英]Xamarin Tabbed Page Content Other than Tab

Quick question,快速提问,

In Xamarin Forms, when using a Tabbed Page, is there any way for there to be content that remains static between the tabs (other than the tabbar itself)?在 Xamarin Forms 中,当使用选项卡式页面时,有没有办法让选项卡之间保留 static 的内容(除了选项卡本身)?

For example, if I have a TabbedPage with 3 children (say Page1 , Page2 and Page3 ), can I add other children to TabbedPage that are not a part of the tab itself, but elsewhere, and stay there between tabs?例如,如果我有一个TabbedPage有 3 个孩子(比如Page1Page2Page3 ),我可以将其他不属于选项卡本身的孩子添加到TabbedPage ,而是在其他地方,并留在选项卡之间吗?

My use for this is I have 3 tabs in my TabbedPage , which is are at the bottom of the page.我的用途是我的TabbedPage中有 3 个标签,位于页面底部。 I would like a settings button in the top-right of each page, without having to create the same content multiple times in each page that is a child of the TabbedPage .我想在每个页面的右上角有一个设置按钮,而不必在每个作为TabbedPage子页面的页面中多次创建相同的内容。

<TabbedPage xlmns="...>
    [Content Here that remains between all tabs, but not a part of the tabbar itself]
    <local:Page1>
    <local:Page2>
    <local:Page3>
</TabbedPage>

Is there some way of doing this easily?有什么方法可以轻松做到这一点吗? Or is there some other method?还是有其他方法? Thanks for any help.谢谢你的帮助。

I would like a settings button in the top-right of each page, without having to create the same content multiple times in each page that is a child of the TabbedPage.我想在每个页面的右上角有一个设置按钮,而不必在作为 TabbedPage 的子页面的每个页面中多次创建相同的内容。

An easy way is using custom control as model.一种简单的方法是使用自定义控件作为 model。 Add the custom control, the button would show in every tabbed pages(page1, page2, page3).添加自定义控件,按钮将显示在每个标签页(page1,page2,page3)中。 If you want to more change on the button, change the custom model, all the changes would show in pages.如果您想对按钮进行更多更改,请更改自定义 model,所有更改都会显示在页面中。

Custom Control: ButtonModel自定义控件:ButtonModel

<Button x:Name="btnModel" Text="Button" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"></Button>

Add this in Page1, Page2, Page3将此添加到第 1 页、第 2 页、第 3 页中

<local:ButtonModel ></local:ButtonModel>

在此处输入图像描述

There are a few methods of fixing this.有几种方法可以解决这个问题。 One of these is outlined in another comment very well, however I found that the Xamarin Forms 'Pure' tabs fitted my needs better.其中一个在另一条评论中得到了很好的概述,但是我发现 Xamarin Forms 'Pure' 选项卡更适合我的需求。 https://www.sharpnado.com/pure-xamarin-forms-tabs/ It was relatively intuitive once I got my head round it and handles integration with mvvm rather well. https://www.sharpnado.com/pure-xamarin-forms-tabs/一旦我了解它并很好地处理与 mvvm 的集成,它就相对直观。 The tabs need nod span the entire page (other than the tabbar) which is exactly what I wanted.标签需要跨越整个页面(除了标签栏),这正是我想要的。

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

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