简体   繁体   English

在Scrollviewer中的## UWP Webview只能在Mobile上工作

[英]c# UWP Webview inside Scrollviewer only not working on Mobile

Got a weird one; 有一个奇怪的; I'm using a webview inside of a scrollviewer (so I can have a stackpanel above the webview that scrolls with it) and my solution works fine on desktop PC and tablet (using both mouse AND touch) but for some reason, on a mobile phone the page just wont scroll! 我在滚动查看器中使用webview(因此我可以在webview上方使用滚动窗口进行滚动)并且我的解决方案在桌面PC和平板电脑上工作正常(使用鼠标和触摸)但出于某种原因,在移动设备上电话页面不会滚动! No idea why. 不知道为什么。 Here is what I have done: 这是我做的:

<ScrollViewer Grid.Row="1" x:Name="theScrollViewer" HorizontalAlignment="Stretch" 
                  ScrollViewer.VerticalScrollBarVisibility="Hidden"
                  HorizontalScrollBarVisibility="Disabled">
            <WebView ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                 ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                 Margin="0" x:Name="theWebView" 
                 Height="2000"
                 DefaultBackgroundColor="#ff2E2E2E" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>    
</ScrollViewer>

and to stop the scrolling in the webview I have added the following to the CSS loaded into the webview: 并停止在webview中滚动我已将以下内容添加到加载到webview中的CSS:

overflow-x:hidden;
overflow-y: hidden

The height property of the webview wont stay 2000; webview的高度属性不会保持2000; but I know for content in a scrollviewer to scroll it needs a height property. 但我知道滚动查看器中的内容滚动它需要一个高度属性。 Anyway this works perfectly with mouse and touch on PCs and tablets, but on Windows 10 Mobile it just doesn't scroll. 无论如何,这与PC和平板电脑上的鼠标和触控完美配合,但在Windows 10 Mobile上它只是不滚动。

Any ideas?? 有任何想法吗??

Anyway this works perfectly with mouse and touch on PCs and tablets, but on Windows 10 Mobile it just doesn't scroll. 无论如何,这与PC和平板电脑上的鼠标和触控完美配合,但在Windows 10 Mobile上它只是不滚动。

I think the problem is that your Webview will not pass the manipulation events to its parent ScrollViewer . 我认为问题是你的Webview不会将操作事件传递给它的父ScrollViewer

On PC, we can scroll the ScrollViewer by dragging Thumb in the ScrollBar or rolling the wheel of mouse, these two interactions can be detected by ScrollViewer . 在PC上,我们可以滚动ScrollViewer通过拖动ThumbScrollBar或滚动鼠标的滚轮,这两种相互作用可以通过被检测到ScrollViewer

But when on mobile, we can only scroll the ScrollViewer by swiping the content area inside the ScrollViewer , since your WebView fill the whole content of ScrollViewer , the swiping gesture will be caught by WebView firstly and not handle to ScrollViewer again, and now your WebView has enough height to hold the web content, the default scroll-function of WebView will also not work. 但是在移动设备上时,我们只能通过滑动ScrollViewer的内容区域来ScrollViewer ,因为您的WebView填充了ScrollViewer的全部内容,滑动手势将首先被WebView捕获而不再处理ScrollViewer ,现在您的WebView有足够的高度来保存Web内容, WebView的默认滚动功能也无法正常工作。

Here is a suggestion: Give a smaller Width to WebView when it works on mobile, and you can scroll the ScrollViewer by swiping on the blank area. 这是一个建议:当它在移动设备上运行时为WebView提供较小的Width ,您可以通过在空白区域上滑动来滚动ScrollViewer But I think this is not a graceful solution to your problem, this will possible make the layout become ugly. 但我认为这不是你问题的优雅解决方案,这可能会使布局变得难看。

Another suggestion is that you can try to create your own Thumb in the right side of your StackPanel and WebView inside the ScrollViewer for scrolling, make this Thumb slid-able and programatically make the ScrollViewer scrolled when the Thumb is translated. 另一个建议是,您可以尝试在ScrollViewer内部的StackPanelWebView的右侧创建自己的Thumb以进行滚动,使此Thumb滑动并以编程方式使ScrollViewerThumb翻译时滚动。

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

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