简体   繁体   English

有没有办法防止 Xamarin Forms 滚动视图在打开选择器控件时自动滚动到最后编辑的条目?

[英]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.

相关问题 Xamarin Forms:防止自动滚动进入焦点 - Xamarin Forms: prevent automatic scrolling on Entry Focus Xamarin Forms ScrollView无法正确滚动 - Xamarin Forms ScrollView is not scrolling correctly 有没有办法验证 Xamarin forms 中的空控件选择器(接收 integer 值)? - Is there a way to validate an empty control picker (that receives an integer value) in Xamarin forms? 在 Xamarin.Forms 发生页面转换时自动打开选择器 - Open a picker automatically when a page transition occurs at Xamarin.Forms 屏蔽的Xamarin.forms入口控件 - Masked entry control Xamarin.forms 在 Xamarin Forms 中更改 Entry 控件的焦点颜色 - Change focus color of Entry control in Xamarin Forms Xamarin Forms-Entry、Picker 等在从后台恢复应用程序或解锁手机后失去其价值 - Xamarin Forms- Entry, Picker etc losing its values after resuming app from background or unlocking phone xamarin forms 选择器值的正确绑定方法 - Correct way of binding xamarin forms picker value xamarin 表单 - 与选择器的双向绑定 - 为什么我不能从后面的代码更新选择器? - xamarin forms - two way binding with a picker - why cant I update a picker from code behind? 是否可以阻止第一个条目在 Xamarin Forms 的 ScrollView 中获得焦点 - Is it possible to stop the first Entry getting Focus in a ScrollView in Xamarin Forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM