I have created custom control as :
`<?xml version="1.0" encoding="UTF-8"?>
<ViewCell.View>
<StackLayout Spacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" >
<StackLayout.Orientation>
<OnPlatform x:TypeArguments="StackOrientation" iOS="Horizontal" Android="Vertical" />
</StackLayout.Orientation>
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="5,10,5,10" Android="5,0,0,0" />
</StackLayout.Padding>
<Label x:Name="thisLabel"
Text="{Binding Label, Source={x:Reference thisExtendedEntryCell}}"
HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" FontSize="18">
<Label.Margin>
<OnPlatform x:TypeArguments="Thickness" iOS="12,0,0,0" Android="0"></OnPlatform>
</Label.Margin>
</Label>
<Entry x:Name="EntryControls"
Text="{Binding Text, Source={x:Reference thisExtendedEntryCell}}"
Placeholder="{Binding Placeholder, Source={x:Reference thisExtendedEntryCell}}"
IsEnabled="{Binding IsEnabled, Source={x:Reference thisExtendedEntryCell}}"
TextChanged="OnTextChanged"
VerticalOptions="CenterAndExpand"
HorizontalTextAlignment="Start">
</Entry>
</StackLayout>
</ViewCell.View>
`
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Sample
{
public partial class SampleEntryControl : ViewCell
{
public static readonly BindableProperty LabelProperty = BindableProperty.Create(nameof(Label), typeof(string), typeof(SampleEntryControl), null, BindingMode.TwoWay);
if IOS
private const double DEFAULT_LABEL_WIDTH = 100;
public static readonly BindableProperty LabelWidthProperty = BindableProperty.Create(nameof(LabelWidth), typeof(double), typeof(SampleEntryControl), DEFAULT_LABEL_WIDTH, BindingMode.TwoWay);
endif
public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(SampleEntryControl), null, BindingMode.TwoWay);
public static readonly BindableProperty TextMaxSizeProperty = BindableProperty.Create(nameof(TextMaxSize), typeof(double), typeof(SampleEntryControl), double.PositiveInfinity, BindingMode.TwoWay);
public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(SampleEntryControl), null, BindingMode.TwoWay);
public string Label
{
get => (string)GetValue(LabelProperty);
set => SetValue(LabelProperty, value);
}
if IOS
public double LabelWidth
{
get => (double)GetValue(LabelWidthProperty);
set => SetValue(LabelWidthProperty, value);
}
endif
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public double TextMaxSize
{
get => (double)GetValue(TextMaxSizeProperty);
set => SetValue(TextMaxSizeProperty, value);
}
public string Placeholder
{
get => (string)GetValue(PlaceholderProperty);
set => SetValue(PlaceholderProperty, value);
}
public SampleEntryControl()
{
InitializeComponent();
var thisLabel = (Label)this.FindByName("thisLabel");
thisLabel.LineBreakMode = LineBreakMode.TailTruncation;
var EntryControl = (Entry)this.FindByName("EntryControls");
if (Device.RuntimePlatform == Device.iOS)
{
EntryControl.HorizontalOptions = LayoutOptions.EndAndExpand;
EntryControl.WidthRequest = 200;
EntryControl.MinimumWidthRequest = 200;
}
if (Device.RuntimePlatform == Device.Android)
{
thisLabel.Margin = new Thickness(5, 0, 0, 0);
EntryControl.HorizontalOptions = LayoutOptions.FillAndExpand;
}
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
var entry = (Entry)sender;
if (entry.Text.Length > TextMaxSize)
{
string entryText = entry.Text;
entry.TextChanged -= OnTextChanged;
entry.Text = e.OldTextValue;
entry.TextChanged += OnTextChanged;
}
}
}
}`
used it with TableView. Here I set two properties Intend and HasUnevenOdd.
`<?xml version="1.0" encoding="utf-8" ?>
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<TableView Intent="Form" HasUnevenRows="True">
<TableRoot>
<TableSection x:Name="TableSection">
</TableSection>
</TableRoot>
</TableView>
</StackLayout>
`
Bind data as
`using System.Collections.Generic;
using Xamarin.Forms;
namespace Sample
{
public partial class MainPage : ContentPage
{
Dictionary<string, string> CollectionDocument = new Dictionary<string, string>();
public MainPage()
{
InitializeComponent();
SetData();
var tableSection = (TableSection)this.FindByName("TableSection");
foreach (var data in CollectionDocument)
{
var extendedEntryControl = new SampleEntryControl();
extendedEntryControl.TextMaxSize = 256;
extendedEntryControl.Label = data.Key;
extendedEntryControl.Text = string.IsNullOrEmpty(data.Value) ? string.Empty : data.Value;
extendedEntryControl.PropertyChanged += UpdateCustomProperties;
tableSection.Add(extendedEntryControl);
}
}
private void SetData()
{
CollectionDocument.Add("Ajay", "Engineer");
CollectionDocument.Add("Kmal", "Engineer");
CollectionDocument.Add("Vjay", "Engineer");
CollectionDocument.Add("Sajay", "Engineer");
CollectionDocument.Add("samay", "Engineer");
CollectionDocument.Add("Anay", "Engineer");
CollectionDocument.Add("Vinay", "Engineer");
CollectionDocument.Add("Joy", "Engineer");
CollectionDocument.Add("Singh", "Engineer");
CollectionDocument.Add("Morgan", "Engineer");
CollectionDocument.Add("Morean", "Engineer");
CollectionDocument.Add("Jean", "Engineer");
CollectionDocument.Add("S Thing", "Engineer");
CollectionDocument.Add("Vishnu", "Engineer");
CollectionDocument.Add("Dishu", "Engineer");
}
private void UpdateCustomProperties(object sender, System.EventArgs e)
{
//need to check.
}
}
}`
Everything is working fine. But issue is when I try to edit value in the list by tapping on row, I am able to edit few values but last few rows I am unable to edit value and focus is not moving to the entry control.
Please let me know if one is facing same type of issue.
Any help is appreciated.