locked
[UWP]Binding Data between C# and Xaml(UWP,HtmlAgility,Xaml) RRS feed

  • Question

  • Hi guys

    i m back..

    today i wanna ask

    how to bind data which

    i just grabbed with HTMLagility in background(C#)with XAML???

    and make it shown in my app(i meant UWP isnt like Winform App which can use console.writeline to give the output)

    just at those blank position

    and here s part of my code

    public partial class WebForm1 : System.Net.Http.HttpClient
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
                System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
    
                
                var headers = httpClient.DefaultRequestHeaders;
    
                string header = "ie";
                if (!headers.UserAgent.TryParseAdd(header))
                {
                    throw new Exception("Invalid header value: " + header);
                }
    
                header = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
                if (!headers.UserAgent.TryParseAdd(header))
                {
                    throw new Exception("Invalid header value: " + header);
                }
    
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
    
               
                htmlDoc.OptionFixNestedTags = true;
    
                            htmlDoc.LoadHtml(" http://www.google.de");
                 
                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    
    
                }
                else
                {
    
                    if (htmlDoc.DocumentNode != null)
                    {
                        HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
    
                        if (bodyNode != null)
                        {
                            
                        }
                    }
                }
            }
        } }
    and if theres somethin wrong pls tell me


    Wednesday, May 25, 2016 10:38 PM

Answers

  • Hi Clancyli,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools


    I have added tag for you this time, and you would need to add tag by yourself next time.

    Based on your code snippet, there’re some issues in it. First, you’d better use HttpClient which was in “Windows.Web.Http” namesapce.

    Second, you used “htmlDoc.LoadHtml(" http://www.google.de")”, it just loaded the “http://www.google.de” string, not get web content from that url.

    Please refer to this sample for details: Getting web content by Html Agility Pack 

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 26, 2016 8:53 AM
  • @Clancyli,

    >>” Then i wanna bind Tables which i just  grabbed from internet with XAML,do u know how to accopmlish that?”

    If you have got the data of that table, you would need to define a custom class, it contained some properties, such as “Klasse”, “Stunde” etc. You could define the property according to the column’s header.

    After that, you could add this custom class object into ObservableCollection, and specify it to GridView’s itemsource.

    Please refer to this article about Data Binding, Grid View and list view controls for details.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 30, 2016 12:51 PM

All replies

  • Hi Clancyli,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools


    I have added tag for you this time, and you would need to add tag by yourself next time.

    Based on your code snippet, there’re some issues in it. First, you’d better use HttpClient which was in “Windows.Web.Http” namesapce.

    Second, you used “htmlDoc.LoadHtml(" http://www.google.de")”, it just loaded the “http://www.google.de” string, not get web content from that url.

    Please refer to this sample for details: Getting web content by Html Agility Pack 

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 26, 2016 8:53 AM
  • Hi Xavier,

    i used system.net.http cause perhaps i will implant this app to other plantform,i dont know if it works or not,i just saw it from internet

    thanks for ur reply and i ve added somethin in my code

     
    HtmlNode docNodes = htmlDoc.DocumentNode;
    
                HtmlNode navNode = htmlDoc.GetElementbyId("bereichaktionen");
    
                HtmlNode docNode = htmlDoc.DocumentNode.SelectSingleNode("/html/body[@class='ui-widget']/div[@id='main']/div[@id='vplan']/div[@id='bereichaktionen']");
    
                string nodeValue;
    
                nodeValue = (docNode.InnerText);
    
     

    Then i wanna bind Tables which i just  grabbed from internet with XAML,do u know how to accopmlish that?

    there is the origin data from the web

    Thank u very much

    X.L

    Saturday, May 28, 2016 12:27 PM
  • Hi Clancyli,

    Welcome to the Developing Universal Windows apps forum!

    Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools


    I have added tag for you this time, and you would need to add tag by yourself next time.

    Based on your code snippet, there’re some issues in it. First, you’d better use HttpClient which was in “Windows.Web.Http” namesapce.

    Second, you used “htmlDoc.LoadHtml(" http://www.google.de")”, it just loaded the “http://www.google.de” string, not get web content from that url.

    Please refer to this sample for details: Getting web content by Html Agility Pack 

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    my question is up there!
    Saturday, May 28, 2016 12:28 PM
  • @Clancyli,

    >>” Then i wanna bind Tables which i just  grabbed from internet with XAML,do u know how to accopmlish that?”

    If you have got the data of that table, you would need to define a custom class, it contained some properties, such as “Klasse”, “Stunde” etc. You could define the property according to the column’s header.

    After that, you could add this custom class object into ObservableCollection, and specify it to GridView’s itemsource.

    Please refer to this article about Data Binding, Grid View and list view controls for details.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 30, 2016 12:51 PM
  • @Clancyli,

    >>” Then i wanna bind Tables which i just  grabbed from internet with XAML,do u know how to accopmlish that?”

    If you have got the data of that table, you would need to define a custom class, it contained some properties, such as “Klasse”, “Stunde” etc. You could define the property according to the column’s header.

    After that, you could add this custom class object into ObservableCollection, and specify it to GridView’s itemsource.

    Please refer to this article about Data Binding, Grid View and list view controls for details.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Hi Xavier,

    actually my expecting effcet is,that table i created shows exactly same as the original  table,

    which means those lines should also  be included.

    Another Problem is ,the origin table ist not static,which means it could be 2 rows or 10 rows,

    and i dont want make the table manully cause some might be empty , sometimes it could be too short.

    My question is how to make it automatically change...

     htmlDoc.LoadHtml(" http://www.eurogymnasium-waldenburg.de/egw_content/Stunden_Vertretungsplan/home.html");
                HtmlNode docNodes = htmlDoc.DocumentNode;
    
                HtmlNode navNode = htmlDoc.GetElementbyId("tableaktionen");
    
                HtmlNode docNode = htmlDoc.DocumentNode.SelectSingleNode("/html/body[@class='ui-widget']/div[@id='main']/div[@id='vplan']/div[@id='bereichaktionen']");
    
                string nodeValue;
    
                nodeValue = (docNode.InnerText);

    As you can see,i captured by ID "tableaktionen",which contains the whole table

    So , is there a way to bind this table directly to xaml and make it shown?

    i think that would be the easiest way

    If its not possible can u show me how to make it right?

    Thanks for your patience again

    X.L

    Thursday, June 9, 2016 4:13 PM