I have a listview and each row contains a label and an entry. How can I set focus for the entry if a row was tapped. My listview is generated dynamically.
void selected(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null)
{
return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
}
TestReading item = (TestReading)e.SelectedItem;
//comment out if you want to keep selections
ListView lst = (ListView)sender;
lst.SelectedItem = null;
}
I want the soft keyboard to show up whenever user tap a particular row regardless of any position.
Use Tapped
<ListView x:Name="ItemsListView" SeparatorColor="LightGray" BackgroundColor="Green" RowHeight="60">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Tapped="ViewCell_Tapped">
<StackLayout Padding="15, 5, 0, 0" Orientation="Horizontal" BackgroundColor="White">
<Entry x:Name="myEntry" HorizontalOptions="FillAndExpand"/>
<Label Text = "{Binding ItemText}" FontSize="20" TextColor="Black" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
in code behind
private void ViewCell_Tapped(object sender, EventArgs e)
{
ViewCell vs = (ViewCell)sender;
var entry = vs.FindByName<Entry>("myEntry");
entry?.Focus();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With