A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
Hello @Dave Lyons ,
Welcome to our Microsoft Q&A platform!
To set data binding for the tableView from the model class, it's unnecessary to add these properties such as 'Text, Placeholder, Keyboard' in the custom cell class. You could pass the value via the model parameters and binding. Here is the sample code, you could refer to:
<!--Page.xaml-->
<TableView x:Name="tvView" Intent="Settings" BackgroundColor="WhiteSmoke" HasUnevenRows="True">
<TableRoot>
<TableSection Title="Authentication">
<local:CustomCell
BindingContext="{Binding Item_1}"
Validate="true"
HorizontalTextAlignment="End"
BindingProperty="EmailAddress" >
</local:CustomCell>
<local:CustomCell
BindingContext="{Binding Item_2}"
Validate="true"
IsPassword="True"
HorizontalTextAlignment="End"
BindingProperty="Password">
</local:CustomCell>
</TableSection>
</TableRoot>
</TableView>
<!--CustomCell.xaml-->
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="customCell"
x:Class="TestApplication_6.CustomCell">
<StackLayout Orientation="Horizontal" Margin="20,5,10,5">
<Label
Text="{Binding TheLabel}"
TextColor="{Binding TextColor}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Start" />
<Entry HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand"
HorizontalTextAlignment="End"
Text="{Binding TheText}"
Placeholder="{Binding ThePlaceholder}"
Keyboard="{Binding TheKeyboard}" />
</StackLayout>
</ViewCell>
Page.xaml.cs & Model class
public partial class Page2 : ContentPage
{
public TableViewItem Item_1 { get; set; }
public TableViewItem Item_2 { get; set; }
public Page2()
{
InitializeComponent();
Item_1 = new TableViewItem
{
TheLabel = "Email Address.......",
ThePlaceholder = "Email Address",
TheKeyboard = Keyboard.Email
};
Item_2 = new TableViewItem
{
TheLabel = "Password",
ThePlaceholder = "Password",
};
BindingContext = this;
}
}
public class TableViewItem
{
public string TheLabel { get; set; }
public string TheText { get; set; }
public string ThePlaceholder { get; set; }
public Keyboard TheKeyboard { get; set; }
}
From your posted code, it seems that the tableView displays the same template in each cell. Do you want to display the same template in the tableView? TableView aims to display the data or choices where there are rows that don't share the same template. ListView and CollectionView will a better choice to display the same template.
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.