Xamarin.forms 未从ViewModel显示extendedWebView

Xamarin.forms 未从ViewModel显示extendedWebView,xamarin.forms,Xamarin.forms,我有webView,我通过ViewModel绑定它,当我调试它时,我知道它的值在那里,但我看不到它。我把它设置在视图的后面,所以我知道一切正常,但我不能从ViewModel显示它。有什么建议吗 XAML 视图模型 private static HtmlWebViewSource htmlSourceExplanation = new HtmlWebViewSource(); private ExtendedWebView _en; public ExtendedWebVi

我有webView,我通过ViewModel绑定它,当我调试它时,我知道它的值在那里,但我看不到它。我把它设置在视图的后面,所以我知道一切正常,但我不能从ViewModel显示它。有什么建议吗

XAML

视图模型

 private static HtmlWebViewSource htmlSourceExplanation = new HtmlWebViewSource();
      private ExtendedWebView _en;
     public ExtendedWebView EN
            {
                get { return _en; }
                set
                {
                    _en = value;

                    NotifyPropertyChanged(nameof(_en));
                }
            }

     private void SetNameAndGrammarDetail(string text, string text2)
            {
                int size = CustomFontSize;
                var style = "<style>.text{ font-size:" + size + "px !important; }</style>";

                htmlSourceName.Html = style + "<div class=\"text\"><div>" + text + "</div><div>" + text2 + "</div></div>";
                EN.Source = htmlSourceName;

                EN.BindingContextChanged += (sender, args) =>
                {
                    htmlSourceName.BindingContext = htmlSourceName.BindingContext;
                };
            }
私有静态HtmlWebViewSource HTMLSourceExplainion=new HtmlWebViewSource();
私有扩展网络视图;
公共扩展网络视图
{
获取{return\u en;}
设置
{
_en=值;
NotifyPropertyChanged(名称(_en));
}
}
私有void setName和grammardeail(字符串文本,字符串文本2)
{
int size=CustomFontSize;
var style=“.text{font size:+size+”px!重要;}”;
Html=style+“”+text+“”+text2+“”;
EN.Source=htmlSourceName;
EN.BindingContextChanged+=(发送方,参数)=>
{
htmlSourceName.BindingContext=htmlSourceName.BindingContext;
};
}

您正在将一个
WebView.Source
从XAML绑定到一个属性
EN
,该属性只是在ViewModel中创建的另一个WebView

您要做的是将
WebView.Source
(在XAML中定义)绑定到HTML代码或URL

Gerald Versluis的回答完美地描述了如何做到这一点:


我看到您在视图模型中将ExtendedWebView作为属性公开。事情不是这样的。您基本上是将WebView.Source(从XAML)设置为新的WebView。我认为你应该公开HtmlText并将源属性绑定到它。你能告诉我怎么做吗?
public Dictionary()
        {

            InitializeComponent();
            BindingContext = new DictionaryViewModel();
}
 private static HtmlWebViewSource htmlSourceExplanation = new HtmlWebViewSource();
      private ExtendedWebView _en;
     public ExtendedWebView EN
            {
                get { return _en; }
                set
                {
                    _en = value;

                    NotifyPropertyChanged(nameof(_en));
                }
            }

     private void SetNameAndGrammarDetail(string text, string text2)
            {
                int size = CustomFontSize;
                var style = "<style>.text{ font-size:" + size + "px !important; }</style>";

                htmlSourceName.Html = style + "<div class=\"text\"><div>" + text + "</div><div>" + text2 + "</div></div>";
                EN.Source = htmlSourceName;

                EN.BindingContextChanged += (sender, args) =>
                {
                    htmlSourceName.BindingContext = htmlSourceName.BindingContext;
                };
            }