简体   繁体   English

如何滚动 Firemonkey TListBox 而不在其控件中捕获焦点?

[英]How to scroll Firemonkey TListBox without capturing focus in its controls?

I have a TListBox with controls in each item, such as TEdit , TComboBox , TSwitch , etc, aligned to the right.我有一个TComboBox ,每个项目中都有一个TListBox ,例如TEditTComboBoxTSwitch等,并与右侧对齐。 There are about 20 items in this list, so it extends beyond the screen, and thus user needs to scroll (by sliding finger) to get to the bottom.这个列表大约有20个项目,所以它超出了屏幕,因此用户需要滚动(通过滑动手指)才能到达底部。

The problem is that even in a quick gesture, if user swipes their finger initially on one of these controls, that control takes focus and the list doesn't scroll.问题是,即使在快速手势中,如果用户最初在这些控件之一上滑动手指,则该控件会获得焦点并且列表不会滚动。 Currently, the only way to scroll up or down is to swipe the finger on the left side of the list, where there aren't any controls.目前,向上或向下滚动的唯一方法是在没有任何控件的列表左侧滑动手指。 I could disable HitTest or CanFocus , but then that control would never get focus, even when the user wants to actually tap on it.可以禁用HitTestCanFocus ,但是即使用户想要实际点击它,该控件也永远不会获得焦点。

How can I allow user to swipe up or down on these controls to scroll the list without that control taking focus?如何允许用户在这些控件上向上或向下滑动以滚动列表,该控件不会获得焦点?

I had the same issue.我有同样的问题。

To solve that insted using a TListBox I used a TVertScrollBox with a layout inside.为了使用 TListBox 解决这个问题,我使用了一个内部有布局的 TVertScrollBox。

Each control is align to top and, to make it work, I needed a VKVertScrollBox from: https://github.com/DelphiWorlds/KastriFree/tree/master/Demos/VKVertScrollbox每个控件都与顶部对齐,为了使其工作,我需要一个 VKVertScrollBox 来自: https : //github.com/DelphiWorlds/KastriFree/tree/master/Demos/VKVertScrollbox

Doing so you will have a scrollable list of components where you can swipe your finger down and see it moving.这样做您将拥有一个可滚动的组件列表,您可以在其中向下滑动手指并查看它的移动。

Besides, to avoid the entering and getFocus on each component when swiping you can use a helper on each component to catch the movement by overriding MouseDown, MouseMove and MouseUp and prevent entering overriding doEnter (also overrited) if it is moving (catched on MouseMove method).此外,为了避免在滑动时在每个组件上输入和 getFocus,您可以在每个组件上使用帮助程序通过覆盖 MouseDown、MouseMove 和 MouseUp 来捕捉移动,并防止进入覆盖 doEnter(也被覆盖)如果它正在移动(在 MouseMove 方法上捕捉) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM