Xamarin Tabbed Page Content Other than Tab

我是研究僧i 提交于 2021-02-11 15:52:32

问题


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)?

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?

My use for this is I have 3 tabs in my TabbedPage, which is are at the bottom of the page. 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 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.


回答1:


You need to check this and create your own control template

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/control-templates/




回答2:


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.

An easy way is using custom control as model. Add the custom control, the button would show in every tabbed pages(page1, page2, page3). If you want to more change on the button, change the custom model, all the changes would show in pages.

Custom Control: ButtonModel

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

Add this in Page1, Page2, Page3

<local:ButtonModel ></local:ButtonModel>




回答3:


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. 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. The tabs need nod span the entire page (other than the tabbar) which is exactly what I wanted.



来源:https://stackoverflow.com/questions/58903845/xamarin-tabbed-page-content-other-than-tab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!