英文:
How to custom WebView scroll behavior in MAUI?
问题
我在一个ContentPage中开发了一个使用WebView呈现HTML内容和使用CollectionView呈现评论列表的应用程序。
伪代码如下:
<ContentPage>
<ScrollView>
<WebView x:Name="WebView" Source="{Binding Source}"></WebView>
<CollectionView ItemsSource="{Binding Comments}"></CollectionView>
</ScrollView>
</ContentPage>
我希望WebView和CollectionView共享相同的ScrollView。但是WebView中没有事件和属性。我不知道从哪里开始。
图示:
对不起,我没有明确问题,让我再解释一遍。
这是我的原型,红色区域呈现HTML页面,灰色区域呈现带有评论的CollectionView,它们共享相同的黄色滚动条。
WebView始终将其高度拉伸到其内容,因此没有滚动条。
问题在于Maui中,我不知道如何禁用WebView的滚动事件。当我在WebView中点击时,无法触发滚动条。
谢谢。
英文:
I developed an app for rendering HTML content with WebView and comments list with CollectionView in a ContentPage.
the pseudo-code like this:
<ContentPage>
<ScrollView>
<WebView x:Nam="WebView" Source={Binding Source} ></WebView>
<CollectionView ItemsSource={Comments} > </CollectionView>
</ScrollView>
</ContentPage>
I hope the WebView and CollectionView shared the same ScrollView. But there is no event and properties in WebView. I don't know where to start
=======
The illustration:
I'm sorry for not classifying the problem, let me illustrate it again.
This is my prototype, the red zone renders an HTML page, and the grey zone renders a CollectionView with comments, they share the same
yellow scrollbar.
The WebView always stretches its height to its content, so there is no scrollbar.
The problem is in Maui, I don't know how to disable the web view scroll down/up event. when I tap in WebView, it can not trigger the scrollbar.
Thanks.
答案1
得分: 1
关于 ScrollView,您可以参考官方文档:ScrollView。文档中提到:
ScrollView 对象不应嵌套。此外,ScrollView 对象不应与其他提供滚动功能的控件嵌套,如 CollectionView、ListView 和 WebView。
但是,您可以将 WebView 和 CollectionView 放入 StackLayout 中。StackLayout 通常是 ScrollView 的子元素。
<ScrollView>
<StackLayout>
<WebView Source="https://learn.microsoft.com/dotnet/maui"/>
<CollectionView x:Name="coll" >
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}" x:Name="nn">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
<x:String>monotouch</x:String>
<x:String>monorail</x:String>
<x:String>monodevelop</x:String>
<x:String>monotone</x:String>
<x:String>monopoly</x:String>
<x:String>monomodal</x:String>
<x:String>mononucleosis</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
</StackLayout>
</ScrollView>
英文:
For ScrollView you can refer to the official doc: ScrollView. It said that:
> ScrollView objects should not be nested. In addition, ScrollView objects should not be nested with other controls that provide scrolling, such as CollectionView, ListView, and WebView.
However, you can put WebView and CollectionView into StackLayout. A StackLayout will often be the child of a ScrollView.
<ScrollView>
<StackLayout>
<WebView Source="https://learn.microsoft.com/dotnet/maui"/>
<CollectionView x:Name="coll" >
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}" x:Name="nn">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
<x:String>monotouch</x:String>
<x:String>monorail</x:String>
<x:String>monodevelop</x:String>
<x:String>monotone</x:String>
<x:String>monopoly</x:String>
<x:String>monomodal</x:String>
<x:String>mononucleosis</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
</StackLayout>
</ScrollView>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论