c# - uwp programmatically scroll WebView up and down -


i'm creating simple news feed, , user can open webview see details of news, reason want user can use buttons control webview scroll , down instead of using scrollviewer, have creat webview show details don't know how scroll , down using buttons

for reason want user can use buttons control webview scroll , down instead of using scrollviewer.

for requirement, use invokescriptasync method notify javascrip invoke custom scroll method. more please refer interacting webview content. , have created sample achieve simple page scrolling. please refer following code:

htmlpage

<body>     <div id="test" style="width: 600px;height: 400px;padding: 10px;margin: 10px;border: 1px solid black;overflow:scroll;font-size:15px;line-height:200px;">         content     </div>     <script type="text/javascript">         function scrolldownbtn() {             test.scrolltop += 10;         }          function scrollupbtn() {             test.scrolltop -= 10;         }     </script> </body> 

mainpage.xaml

<webview x:name="mywebview" source="ms-appx-web:///newspage.html" /> <stackpanel     grid.row="1"     horizontalalignment="center"     orientation="horizontal">     <button         x:name="scrollup"         margin="10"         click="scrollup_click"         content="scrollup" />     <button         x:name="scrolldown"         margin="10"         click="scrolldown_click"         content="scrolldown" /> </stackpanel> 

mainpage.xaml.cs

private async void scrollup_click(object sender, routedeventargs e) {     await mywebview.invokescriptasync("scrollupbtn", null); }  private async void scrolldown_click(object sender, routedeventargs e) {     await mywebview.invokescriptasync("scrolldownbtn", null); } 

enter image description here code sample.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -