无法将WebView绑定到响应列表

时间:2018-07-10 10:00:48

标签: c# webview xamarin.forms


我是Xamarin.Forms的新手,无法将服务响应绑定到WebView。
我有一个包含Webview的帖子查看页面,我得到的答复是文本,列表和KeyValuePair的组合
实际上,我无法将列表响应绑定到该单个Webview中,也无法将其导航到我从服务获得的新相关帖子。
我将附加XAML页面和ContentPage cs的屏幕快照,在其中创建了要绑定的html代码。

This is My XAML Page

This is how I bind the responses and created html

This is how the post looks

I need them to have redirected to a new individual post when I click on any of the links. Right now it shows the complete list view in response with the path it needs to navigate to.

请帮助我了解我是否做错了事。

1 个答案:

答案 0 :(得分:0)

我设法通过将整个响应串联在字符串中来使其工作。 以下是帮助我实现这一目标的代码-

String getHtml()                 {                     var bodyStyle =“ body {height:100%;} p {text-align:left; color:#191919;} filter {background-color:#191919;} a:link”                         +“ {color:#2588B0; background-color:transparent} a:已访问{color:#0099CC; background-color:transparent}”                         +“ a:hover {color:#0099CC; background-color:transparent} a:ative {color:#0099CC; background-color:transparent} span {background-color:yellow; color:black} customRight {float:right} “; // window.onload = function(e){alert('prevented');}

                var refs = bodyStyle;

                refs = refs + "<center><h4>" + response.Title + "<h4></center>";

                if (response.Pc.Count > 0)
                {
                    refs = refs + "<center><u>" + PrimaryCitation +
                        "</a></u></center><br>";
                }

                if (string.IsNullOrWhiteSpace(response.Cn))
                {
                    refs = refs + "<center>" + response.Cn + "</center><br>";

                }

                if (response.Judges.Count() > 0)
                {
                    refs = refs + "<center> <strong>Coram:</strong> " + JudgesN + "</center><br>";
                }

                if (string.IsNullOrWhiteSpace(response.JGD.ToString()))
                {
                    refs = refs + "<center> <strong>Decided On:</strong> " + response.JGD + "</center><br>";
                }

                if(string.IsNullOrWhiteSpace(response.AppealType) )
                {
                    refs = refs + "<center> <strong>Appeal Type: </strong>" + response.AppealType + "</center><br>";
                }

                if (response.Appellants != null)
                {
                    refs = refs + "<left><b>" + Appeallants + "</b></left>";
                    refs = refs + "<customRight>APPELLANT</customRight><br>";

                }
                refs = refs + "<center>VERSUS</center>";

                if (response.Respondants != null)
                {
                    refs = refs + "<left><b>" + Respondants + "</b></left>";
                    refs = refs + "<customRight>RESPONDENT</customRight><br><br>";
                }

                if (string.IsNullOrWhiteSpace(response.FinalVerdict))
                {
                    refs = refs + "<center> <strong>Final Verdict:</strong> " + response.FinalVerdict + "</center><br>";
                }

                if (string.IsNullOrWhiteSpace(response.Headnote))
                {
                    refs = refs + "<p> <strong>Head Note:</strong><br/> " + response.Headnote.ToLowerInvariant() + "</p><br>";
                }

                if(response.Refs != null)
                {
                    refs = refs + "<left><b>Refered Jdgmts: </b></left><br>";
                    foreach(var obj in response.Refs) 
                        {
                        if(obj.Jid == null) {
                            refs = refs + "<p style='font-size:13px;'>"
                                + obj.Title
                                +"</p>";
                        }
                        /*else
                        {
                            refs = refs + "<p style='font-size:13px;'>" + "<a href=\""
                                + obj.Jid
                                     + "\" target=\"_blank\">"
                                     + obj.Title
                                + "</a>"
                                + "</p>";
                       }*/
                        else
                        {
                            refs = refs + "<p style='font-size:13px;'>" + "<a href=\""
                                + obj.Jid
                                     + "\" target=\"_blank\" onClick=\"(function(e){alert('e is here'); loadJt(obj.Jid);return false;})(); return false;\">"
                                     + obj.Title
                                + "</a>"
                                + "</p>";
                        }


                if(response.AtRefrs != null)
                {
                    refs = refs + "<left><b>Refered Ats: </b></left><br>";
                    foreach(var refAt in response.AtRefrs) {
                        if(refAt.AtId == null) {
                            refs += "<p style='font-size:13px;'>"
                                + refAt.At + "</p>";
                        }
                        else
                        {
                            refs += "<p style='font-size:13px;'>" + "<a href=\""
                                + "@" + refAt.AtId
                                + "\" target=\"_blank\">"
                                + refAt.At + "</a>";
                        }
                        foreach(var refSec in refAt.S) {
                            if(refSec.Ssi != null) {
                                refs += " " + refSec.St;
                            }
                            else
                            {
                                refs += " " + "<a href=\""
                                    + "@" + (refSec.SId)
                                    + "\" target=\"_blank\">"
                                    + refSection.Section
                                    + "</a>";
                            }
                        }
                        refs += "</p>";

                    }
                }

                refs = refs + "<left><b>Jdgmt: </b></left>";
                var jdgmt = "<p>" + response.DJdes
                                                         + (response.Text)+ "</p>";

                jdgmt = jdgmt.Replace("^^^", "<br/><br/>");
                jdgmt = jdgmt.Replace("<SPARA>", "<p>");
                jdgmt = jdgmt.Replace("</SPARA>", "</p>");

                refs = refs + jdgmt;
                refs = refs + "</body></html>";

                return refs;
            }

            data.Source = new HtmlWebViewSource { Html = getHtml(), BaseUrl="http://url.com/", BindingContext = response };