发布:2021/10/20 15:23:23作者:管理员 来源:本站 浏览次数:1071
我是xamarin的新手,并一直在尝试解决此问题的方法:我有一个堆栈布局,其中包含N个条目,具体取决于用户的需求.
<ScrollView>
<StackLayout x:Name="Visual" Padding="5,5,5,20">
<StackLayout x:Name="EntradasPeso" />
</StackLayout>
</ScrollView>
我通过循环动态添加它们:
//calculo.Qnt_amostra is the ammount of entries that the view has.
for (int i = 1; i <= (int)calculo.Qnt_amostra; i++)
{
CustomEntry peso = new CustomEntry();
peso.IsNumeric = true;
peso.Placeholder = $"Peso da {i}° amostra";
peso.Keyboard = Keyboard.Numeric;
peso.Completed += Peso_Completed;
EntradasPeso.Children.Add(peso);
}
问题是,他们没有x:Name(据我所知).
因此,如何设置此自定义条目以将视图中的下一个元素聚焦?请记住,我不能这样做:
EntradasPeso.Focus(nameofentry)
谁能帮我?
private void Peso_Completed(object sender, EventArgs e)
{
// focus to next entry
}
private void Peso_Completed(object sender, EventArgs e)
{
var entry = sender as MyEntry; // .. and check for null
var list = (entry.Parent as StackLayout).Children; //assumes a StackLayout
var index = list.IndexOf(entry); // what if IndexOf returns -1?
var nextIndex = (index + 1) >= list.Count ? 0 : index + 1; //first or next element?
var next = list.ElementAt(nextIndex);
next?.Focus();
}
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4