xaml - Xamarin 表单工具栏项在选项卡式页面中出现两次
问题描述
我在标签页中添加了一个名称刷新的工具栏项,下面是标签页的代码
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Xapp;assembly=Xapp"
mc:Ignorable="d"
x:Class="Xapp.HomePage">
<TabbedPage.ToolbarItems>
<ToolbarItem x:Name="Refresh" Text="Refresh" />
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<NavigationPage Title="report">
<x:Arguments>
<local:ReportPage>
<StackLayout>
<Label Text="In:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding CountIn}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="Out:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding CountOut}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="Date:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding createdon}" FontSize="Medium" FontAttributes="Bold" />
</StackLayout>
</local:ReportPage>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="history">
<x:Arguments>
<local:HistoryPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
问题是工具栏中出现两次刷新,如下图所示:
解决方案
如果 App 的MainPage是TabbedPage。您无需将其设置为NavigationPage。在应用程序中。
修改 App.Xaml.CS 中的代码
public App()
{
InitializeComponent();
MainPage = new HomePage();
}
更新
从ContentPage导航到TabbedPage不是一个好的设计 。
所以修改代码为
App.Current.MainPage = new HomePage();
代替page.Navigation.PushAsync(new HomePage());
推荐阅读
- ruby-on-rails - 如何使用 Icalendar::HasComponents?
- sql - 如何在 SQL 中捕获每天创建和删除的表的详细信息?
- matlab - 使用 matlab 创建和绘制分布图
- visual-studio - Visual Studio 中的报表生成器 Nuget
- c++ - C++中TCP套接字的recv函数
- android - Firebase 数据库突然停止在少数安卓设备上运行
- woocommerce - 通过 Api 在 WooCommerce 中插入产品插件
- npm-install - 无法从“init.js”中找到模块“detox/runners/jest/adapter” - 排毒
- python-3.x - tensorflow不使用gpu - 素数程序
- oracle11g - oracle内部连接过程