C# Xamarin表单具有选项卡式页面,每个选项卡式页面中都有数据表单输入页面
我是Xamarin的新手。我有一个Xamarin forrms应用程序,带有选项卡式页面,它有3个选项卡,每个选项卡都有一个数据输入表单,所有数据输入表单都应该传递给webapi DTO实体类。当我单击第三个选项卡上的提交按钮时,如何从3个选项卡中的3个页面收集所有数据并发布数据。实现这一点的最佳方式是什么?我的密码在下面 在模型中DTO FamilyTreeMasterC# Xamarin表单具有选项卡式页面,每个选项卡式页面中都有数据表单输入页面,c#,xamarin,xamarin.forms,xamarin-forms-4,C#,Xamarin,Xamarin.forms,Xamarin Forms 4,我是Xamarin的新手。我有一个Xamarin forrms应用程序,带有选项卡式页面,它有3个选项卡,每个选项卡都有一个数据输入表单,所有数据输入表单都应该传递给webapi DTO实体类。当我单击第三个选项卡上的提交按钮时,如何从3个选项卡中的3个页面收集所有数据并发布数据。实现这一点的最佳方式是什么?我的密码在下面 在模型中DTO FamilyTreeMaster using System; using System
using System;
using System.Collections.Generic;
using System.Text;
namespace FamilyTreeApp.Models
{
public class DTOFamilyTreeMaster
{
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Nullable<int> Age { get; set; }
public string Profession { get; set; }
public string FatherFirstName { get; set; }
public string FatherLastName { get; set; }
public string MotherFirstName { get; set; }
public string MotherLastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Spouse1_FirstName { get; set; }
public string Spouse1_LastName { get; set; }
public string Spouse2_FirstName { get; set; }
public string Spouse2_LastName { get; set; }
public string Spouse3_FirstName { get; set; }
public string Spouse3_LastName { get; set; }
public string Spouse4_FirstName { get; set; }
public string Spouse4_LastName { get; set; }
public string Spouse5_FirstName { get; set; }
public string Spouse5_LastName { get; set; }
public string Son1_FirstName { get; set; }
public string Son1_LastName { get; set; }
public string Son2_FirstName { get; set; }
public string Son2_LastName { get; set; }
public string Son3_FirstName { get; set; }
public string Son3_LastName { get; set; }
public string Son4_FirstName { get; set; }
public string Son4_LastName { get; set; }
public string Son5_FirstName { get; set; }
public string Son5_LastName { get; set; }
public string Son6_FirstName { get; set; }
public string Son6_LastName { get; set; }
public string Son7_FirstName { get; set; }
public string Son7_LastName { get; set; }
public string Son8_FirstName { get; set; }
public string Son8_LastName { get; set; }
public string Son9_FirstName { get; set; }
public string Son9_LastName { get; set; }
public string Son10_FirstName { get; set; }
public string Son10_LastName { get; set; }
public string Daughter1_FirstName { get; set; }
public string Daughter1_LastName { get; set; }
public string Daughter2_FirstName { get; set; }
public string Daughter2_LastName { get; set; }
public string Daughter3_FirstName { get; set; }
public string Daughter3_LastName { get; set; }
public string Daughter4_FirstName { get; set; }
public string Daughter4_LastName { get; set; }
public string Daughter5_FirstName { get; set; }
public string Daughter5_LastName { get; set; }
public string Daughter6_FirstName { get; set; }
public string Daughter6_LastName { get; set; }
public string Daughter7_FirstName { get; set; }
public string Daughter7_LastName { get; set; }
public string Daughter8_FirstName { get; set; }
public string Daughter8_LastName { get; set; }
public string Daughter9_FirstName { get; set; }
public string Daughter9_LastName { get; set; }
public string Daughter10_FirstName { get; set; }
public string Daughter10_LastName { get; set; }
public Nullable<int> MyPosition { get; set; }
public Nullable<int> MyParentPosition { get; set; }
}
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
命名空间FamilyTreeApp.Models
{
公共类DTOFAALYTREEMASTER
{
公共字符串标题{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共可空年龄{get;set;}
公共字符串职业{get;set;}
公共字符串FatherFirstName{get;set;}
公共字符串父lastname{get;set;}
公共字符串MotherFirstName{get;set;}
公共字符串MotherLastName{get;set;}
公共字符串地址1{get;set;}
公共字符串地址2{get;set;}
公共字符串City{get;set;}
公共字符串状态{get;set;}
公共字符串Zip{get;set;}
公共字符串国家{get;set;}
公用字符串电话{get;set;}
公共字符串1_FirstName{get;set;}
公共字符串spoutse1_LastName{get;set;}
公共字符串spoose2_FirstName{get;set;}
公共字符串spoose2_LastName{get;set;}
公共字符串spoose3_FirstName{get;set;}
公共字符串spoose3_LastName{get;set;}
公共字符串spoose4_FirstName{get;set;}
公共字符串spoose4_LastName{get;set;}
公共字符串spoose5_FirstName{get;set;}
公共字符串spoutse5_LastName{get;set;}
公共字符串Son1_FirstName{get;set;}
公共字符串Son1_LastName{get;set;}
公共字符串Son2_FirstName{get;set;}
公共字符串Son2_LastName{get;set;}
公共字符串Son3_FirstName{get;set;}
公共字符串Son3_LastName{get;set;}
公共字符串Son4_FirstName{get;set;}
公共字符串Son4_LastName{get;set;}
公共字符串Son5_FirstName{get;set;}
公共字符串Son5_LastName{get;set;}
公共字符串Son6_FirstName{get;set;}
公共字符串Son6_LastName{get;set;}
公共字符串Son7_FirstName{get;set;}
公共字符串Son7_LastName{get;set;}
公共字符串Son8_FirstName{get;set;}
公共字符串Son8_LastName{get;set;}
公共字符串Son9_FirstName{get;set;}
公共字符串Son9_LastName{get;set;}
公共字符串Son10_FirstName{get;set;}
公共字符串Son10_LastName{get;set;}
公共字符串子字符串1_FirstName{get;set;}
公共字符串Daughter1_LastName{get;set;}
公共字符串Daughter2_FirstName{get;set;}
公共字符串Daughter2_LastName{get;set;}
公共字符串子3_FirstName{get;set;}
公共字符串Daughter3_LastName{get;set;}
公共字符串子字符串4_FirstName{get;set;}
公共字符串子字符串4_LastName{get;set;}
公共字符串Daughter5_FirstName{get;set;}
公共字符串Daughter5_LastName{get;set;}
公共字符串子字符串6_FirstName{get;set;}
公共字符串子字符串6_LastName{get;set;}
公共字符串子字符串7_FirstName{get;set;}
公共字符串子字符串7_LastName{get;set;}
公共字符串子字符串8_FirstName{get;set;}
公共字符串子字符串8_LastName{get;set;}
公共字符串子字符串9_FirstName{get;set;}
公共字符串子字符串9_LastName{get;set;}
公共字符串子字符串10_FirstName{get;set;}
公共字符串子字符串10_LastName{get;set;}
公共可为空的MyPosition{get;set;}
公共可为空的MyParentPosition{get;set;}
}
}
视图中的选项卡式页面
用户信息选项卡页
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage Visual="Material"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:FamilyTreeApp.Pages"
x:Class="FamilyTreeApp.Pages.UserInfoTabbedPage">
<local:UserTabbedPage Title ="User"
Icon ="user.png"/>
<local:UserSpousePage Title ="Family"
Icon ="sharp_group_add_black_18.png"/>
<local:UserChildrenTabbedPage class="material-icons" Title ="User"
Icon ="user.png"/>
</TabbedPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage Visual="Material"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FamilyTreeApp.Pages.UserTabbedPage">
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Basic">
<EntryCell Placeholder="Title" Text="{Binding Title}"></EntryCell>
<EntryCell Placeholder="First Name" Text="{Binding FirstName}"></EntryCell>
<EntryCell Placeholder="Last Name" Text="{Binding LastName}"></EntryCell>
<EntryCell Placeholder="Nick Name" Text="{Binding NickName}"></EntryCell>
<EntryCell Placeholder="Age" Text="{Binding Age}"></EntryCell>
<EntryCell Placeholder="Profession" Text="{Binding Profession}"></EntryCell>
</TableSection>
<TableSection Title="Contact">
<EntryCell Placeholder="Address 1" Text="{Binding Address1}"></EntryCell>
<EntryCell Placeholder="Address 2" Text="{Binding Address2}"></EntryCell>
<EntryCell Placeholder="City" Text="{Binding City}"></EntryCell>
<EntryCell Placeholder="State" Text="{Binding State}"></EntryCell>
<EntryCell Placeholder="Zip" Text="{Binding Zip}" Keyboard="Numeric"></EntryCell>
<EntryCell Placeholder="Country" Text="{Binding Country}"></EntryCell>
<EntryCell Placeholder="Phone" Text="{Binding Phone}" Keyboard="Numeric"></EntryCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage Visual="Material" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
x:Class="FamilyTreeApp.Pages.UserChildrenTabbedPage">
<AbsoluteLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<TableView Intent="Form">
<TableRoot>
<TableSection x:Name="Sons" Title="Son(s)">
<ViewCell>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperSon},Path=Value}"/>
<Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperSon" Increment="1" Maximum="10" Minimum="1" >
</Stepper>
<ic:CircleImage Grid.Row="0" Grid.Column="2" Source="sharp_group_add_black_18.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnstepperSonValueChanged" />
</Image.GestureRecognizers>
</ic:CircleImage>
</Grid>
</StackLayout>
</ViewCell>
</TableSection>
<TableSection x:Name="Daughters" Title="Daughter(s)">
<ViewCell>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperDaughter},Path=Value}"/>
<Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperDaughter" Increment="1" Maximum="10" Minimum="1" >
</Stepper>
<ic:CircleImage Grid.Row="0" Grid.Column="2" Source="sharp_group_add_black_18.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnstepperDaughterValueChanged" />
</Image.GestureRecognizers>
</ic:CircleImage>
</Grid>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
<StackLayout
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="1,1,0.25,0.25">
<StackLayout HorizontalOptions="End" VerticalOptions="End" Margin="0,0,0,0">
<Button Clicked="OnSubmit" Text="Submit" HorizontalOptions="End"
></Button>
</StackLayout>
</StackLayout>
</AbsoluteLayout>
</ContentPage>
用户选项卡页
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage Visual="Material"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:FamilyTreeApp.Pages"
x:Class="FamilyTreeApp.Pages.UserInfoTabbedPage">
<local:UserTabbedPage Title ="User"
Icon ="user.png"/>
<local:UserSpousePage Title ="Family"
Icon ="sharp_group_add_black_18.png"/>
<local:UserChildrenTabbedPage class="material-icons" Title ="User"
Icon ="user.png"/>
</TabbedPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage Visual="Material"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="FamilyTreeApp.Pages.UserTabbedPage">
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Basic">
<EntryCell Placeholder="Title" Text="{Binding Title}"></EntryCell>
<EntryCell Placeholder="First Name" Text="{Binding FirstName}"></EntryCell>
<EntryCell Placeholder="Last Name" Text="{Binding LastName}"></EntryCell>
<EntryCell Placeholder="Nick Name" Text="{Binding NickName}"></EntryCell>
<EntryCell Placeholder="Age" Text="{Binding Age}"></EntryCell>
<EntryCell Placeholder="Profession" Text="{Binding Profession}"></EntryCell>
</TableSection>
<TableSection Title="Contact">
<EntryCell Placeholder="Address 1" Text="{Binding Address1}"></EntryCell>
<EntryCell Placeholder="Address 2" Text="{Binding Address2}"></EntryCell>
<EntryCell Placeholder="City" Text="{Binding City}"></EntryCell>
<EntryCell Placeholder="State" Text="{Binding State}"></EntryCell>
<EntryCell Placeholder="Zip" Text="{Binding Zip}" Keyboard="Numeric"></EntryCell>
<EntryCell Placeholder="Country" Text="{Binding Country}"></EntryCell>
<EntryCell Placeholder="Phone" Text="{Binding Phone}" Keyboard="Numeric"></EntryCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage Visual="Material" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ic="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
x:Class="FamilyTreeApp.Pages.UserChildrenTabbedPage">
<AbsoluteLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<TableView Intent="Form">
<TableRoot>
<TableSection x:Name="Sons" Title="Son(s)">
<ViewCell>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperSon},Path=Value}"/>
<Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperSon" Increment="1" Maximum="10" Minimum="1" >
</Stepper>
<ic:CircleImage Grid.Row="0" Grid.Column="2" Source="sharp_group_add_black_18.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnstepperSonValueChanged" />
</Image.GestureRecognizers>
</ic:CircleImage>
</Grid>
</StackLayout>
</ViewCell>
</TableSection>
<TableSection x:Name="Daughters" Title="Daughter(s)">
<ViewCell>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Reference stepperDaughter},Path=Value}"/>
<Stepper Grid.Row="0" Grid.Column="1" x:Name="stepperDaughter" Increment="1" Maximum="10" Minimum="1" >
</Stepper>
<ic:CircleImage Grid.Row="0" Grid.Column="2" Source="sharp_group_add_black_18.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnstepperDaughterValueChanged" />
</Image.GestureRecognizers>
</ic:CircleImage>
</Grid>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
<StackLayout
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="1,1,0.25,0.25">
<StackLayout HorizontalOptions="End" VerticalOptions="End" Margin="0,0,0,0">
<Button Clicked="OnSubmit" Text="Submit" HorizontalOptions="End"
></Button>
</StackLayout>
</StackLayout>
</AbsoluteLayout>
</ContentPage>
public class DataManager
{
private static DataManager instance;
// save data of three forms,or you could define them as any other type
public Dictionary<string, string> Forms1 { get; set; }
public Dictionary<string, string> Forms2 { get; set; }
public Dictionary<string, string> Forms3 { get; set; }
private DataManager() { }
public static DataManager Instance
{
get
{
if (instance == null)
{
instance = new DataManager();
}
return instance;
}
}
DataManager.Instance.Forms1 = new Dictionary<string, string>();
for (int i = countDaughters; i <= numCell; i++)
{
DataManager.Instance.Forms1.Add("xxx","xxx");
}
var Form1 = DataManager.Instance.Forms1 ;