Xamarin 表单工具栏项在选项卡式页面中出现两次
Xamarin forms toolbar items occurs two times in the tabbed page
我在标签页中添加了一个名为刷新的工具栏项,下面是标签页的代码
<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());
我在标签页中添加了一个名为刷新的工具栏项,下面是标签页的代码
<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());