【发布时间】:2021-07-09 23:14:45
【问题描述】:
我想遵循 SIP(单一责任原则)。
我创建了下面的TabbedPage,分别有 3 个标签/页面(Page1、Page2 和 Page3),效果很好。
我正在考虑将每个 ContentPage 拆分到其自己的 xaml 文件中,以便其每个 C# 文件 (xaml.cs) 文件也可以处理它自己的 ContentPage,但最后他们需要表现得像一个3页的普通标签视图页面。
我正在考虑这样做,因为每个 ContentPage 必须在一天结束时在其中包含很多东西(代码),这就是为什么我正在考虑将每个 ContentPage 从开始。
不确定在 Xamarin 中是否可行。
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedPageApp.MainPage"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom">
<!--android:TabbedPage.BarItemColor="Black"
android:TabbedPage.BarSelectedItemColor="Red">-->
<ContentPage Title="Page 1" IconImageSource="outline_settings_black_24dp.png">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Welcome to Xamarin - TabbedPage 1" HorizontalTextAlignment="Center" TextColor="Yellow" FontSize="36"/>
<Entry x:Name="entryB" />
<Button x:Name="myButtonCancel" Text="Cancel" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage Title="Page 2" IconImageSource="outline_add_shopping_cart_black_24dp.png">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Welcome to Xamarin - TabbedPage 2" HorizontalTextAlignment="Center" TextColor="Yellow" FontSize="36"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage Title="Page 3" IconImageSource="outline_account_circle_black_24dp.png">
<ContentPage.Content>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="Welcome to Xamarin - TabbedPage 3" HorizontalTextAlignment="Center" TextColor="Yellow" FontSize="36"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</TabbedPage>
【问题讨论】:
标签: xaml xamarin xamarin.forms tabbedpage