[英]Is there a way to prevent a Xamarin Forms scrollview from automatically scrolling to the last edited Entry when a picker control is opened?
I have a setup similar to this:我有一个类似的设置:
<ScrollView>
<StackLayout>
<Entry/>
<Picker/>
<Entry/>
<Entry/>
<Entry/>
<Picker/>
<Picker/>
<Entry/>
<Entry/>
<Entry/>
</StackLayout>
</ScrollView>
Where the Entry and Picker controls are dynamically created and modified.动态创建和修改 Entry 和 Picker 控件的位置。 The problem is that if I type into an Entry and then open one of the Picker controls, the ScrollView scrolls to where the previously edited Entry is in view.问题是,如果我输入一个条目,然后打开其中一个 Picker 控件,则 ScrollView 会滚动到之前编辑的条目所在的位置。 It was getting focus, but I prevented the focus from shifting, yet the ScrollView scrolls and I can't seem to prevent it.它正在获得焦点,但我阻止了焦点转移,但 ScrollView 滚动,我似乎无法阻止它。
I did something similar to Is it possible to stop the first Entry getting Focus in a ScrollView in Xamarin Forms to fix the related issue in UWP, but that solution is not applicable to iOS and Android. I did something similar to Is it possible to stop the first Entry getting Focus in a ScrollView in Xamarin Forms to fix the related issue in UWP, but that solution is not applicable to iOS and Android.
Set the name of StackLayout
.设置StackLayout
的名称。 Foreach the elements in 'StackLayout' and reset the focus. Foreach 'StackLayout' 中的元素并重置焦点。
private void Picker_Focused(object sender, FocusEventArgs e)
{
foreach (var item in stackLayout.Children)
{
if (sender!=item)
{
item.Unfocus();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.