如何在Listview中将焦点设置为Entry? Xamarin形式 [英] How to set focus on Entry inside Listview? Xamarin Forms
本文介绍了如何在Listview中将焦点设置为Entry? Xamarin形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表视图,每一行都包含一个标签和一个条目.如果点击了行,如何设置条目的焦点.我的列表视图是动态生成的.
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.
推荐答案
使用点击式
<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>
后面的代码中
private void ViewCell_Tapped(object sender, EventArgs e)
{
ViewCell vs = (ViewCell)sender;
var entry = vs.FindByName<Entry>("myEntry");
entry?.Focus();
}
这篇关于如何在Listview中将焦点设置为Entry? Xamarin形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文