设置后接收触摸事件StackLayout.TranslateX属性
Receive touch events after settings StackLayout.TranslateX property
我有一个带有 StackLayout 的 ContentView,其中多个 children 大小为屏幕的全宽。换句话说,如果屏幕宽度为 320 而我有五个 children,则内部 StackLayout 将调整为 1600.
在这个 ContentView 中,我有 Next 和 Previous 按钮,单击它们时,会激活内部 StackLayout 的 TranslateX 属性。基本上,我通过在 ContentView 中转换 StackLayout 来创建轮播。我选择这条路线是因为当我修改视图的布局(通过隐藏标签等)时,我在使用 ScrollView 和自定义渲染器时遇到布局问题
但是,我遇到了麻烦。在我设置 TranslateX 属性 后出现的内容没有收到任何点击事件。我相信我可能需要重置一些可点击区域,但我什至不确定从哪里开始。有人有什么建议吗?
我在 Xamarin 的论坛上发布了同样的问题,那里有人回答了。对于正在寻找的人,答案就在这里:https://forums.xamarin.com/discussion/comment/142914/#Comment_142914
如果那个 link 在将来的某个时候由于某种原因停止工作,相关的答案是:
Hit testing is done based on the actual frame of the control determined by layout, but translation happens after layout. Therefore hit testing does not take translation into account. If you want a view to be touchable then you should update its layout directly rather than using translation.
我有一个带有 StackLayout 的 ContentView,其中多个 children 大小为屏幕的全宽。换句话说,如果屏幕宽度为 320 而我有五个 children,则内部 StackLayout 将调整为 1600.
在这个 ContentView 中,我有 Next 和 Previous 按钮,单击它们时,会激活内部 StackLayout 的 TranslateX 属性。基本上,我通过在 ContentView 中转换 StackLayout 来创建轮播。我选择这条路线是因为当我修改视图的布局(通过隐藏标签等)时,我在使用 ScrollView 和自定义渲染器时遇到布局问题
但是,我遇到了麻烦。在我设置 TranslateX 属性 后出现的内容没有收到任何点击事件。我相信我可能需要重置一些可点击区域,但我什至不确定从哪里开始。有人有什么建议吗?
我在 Xamarin 的论坛上发布了同样的问题,那里有人回答了。对于正在寻找的人,答案就在这里:https://forums.xamarin.com/discussion/comment/142914/#Comment_142914
如果那个 link 在将来的某个时候由于某种原因停止工作,相关的答案是:
Hit testing is done based on the actual frame of the control determined by layout, but translation happens after layout. Therefore hit testing does not take translation into account. If you want a view to be touchable then you should update its layout directly rather than using translation.