Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Problem with WebView.

$
0
0

Hi! I'm creating a mobile app of existing webpage. I used HTMLAGILITYPACK to scrap some of data for web page and I'd like to display that data in my app.

Here is my 'scrapper':

    namespace Apka
    {
        public partial class App : Application
        {
            public static string DocumentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            public static string strona = "";                

            public static NavigationPage NavigationPage { get; private set; }
            WebRequest request = HttpWebRequest.Create("wiocha.pl");
            WebResponse response;

            public App()
            {            
                InitializeComponent();        
                starthttp();

                NavigationPage = new NavigationPage(new MainPage());
                RootPage rootPage = new RootPage();
                MenuPage menuPage = new MenuPage(rootPage.vm);

                rootPage.Master = menuPage;
                rootPage.Detail = NavigationPage;
                MainPage = rootPage;        
            }        

            private async void starthttp()
            {        
                response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);

                var html = new HtmlDocument();
                html.Load(response.GetResponseStream());
                var nodes = html.DocumentNode.Descendants("img")
                    .Where(node => node.GetAttributeValue("class", "")
                       .Equals("imageitself")).ToList();       

                foreach (var node in nodes)
                {        
                    strona = strona + node.OuterHtml;        
                }

                System.Diagnostics.Debug.WriteLine(strona);                                      
            }
        }
    }

The result of it printed in console is some of img like:

<img src=''link(i cant paste link because im a new here)'' class=imageitself alt=''blablabla''>

Next, I'm trying to display it on main page so i do something like that:

namespace Apka.View.Pages
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {           
        public MainPage()
        {
            InitializeComponent();

            WebView webView = new WebView
            {
                Source = new HtmlWebViewSource
                {
                    Html = @"<!DOCTYPE html><html><head><style>img { width:100%; }</style><body>" + App.strona + @"</body></html>",
                },
                VerticalOptions = LayoutOptions.FillAndExpand

            };       

            /* ViewModel.Pages.MainPageViewModel vm = new ViewModel.Pages.MainPageViewModel();
             this.BindingContext = vm;*/
        }                  
    }
}

XAML of this page looks like that:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="" (again i cant paste link)
             xmlns:x="" (here too)
             x:Class="Apka.View.Pages.MainPage">    

    <ContentPage.ToolbarItems>
        <ToolbarItem Command="{Binding MenuItem1Command}" />
    </ContentPage.ToolbarItems>
    <ContentPage.Content>

        <StackLayout BackgroundColor="#505050" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">        
        </StackLayout>

    </ContentPage.Content>
</ContentPage>

The problem is, it does nothing. I run app and webview doesn't work. What should I do to display these images on my page.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>