Xamarin.forms 未从ViewModel显示extendedWebView
我有webView,我通过ViewModel绑定它,当我调试它时,我知道它的值在那里,但我看不到它。我把它设置在视图的后面,所以我知道一切正常,但我不能从ViewModel显示它。有什么建议吗 XAML 视图模型Xamarin.forms 未从ViewModel显示extendedWebView,xamarin.forms,Xamarin.forms,我有webView,我通过ViewModel绑定它,当我调试它时,我知道它的值在那里,但我看不到它。我把它设置在视图的后面,所以我知道一切正常,但我不能从ViewModel显示它。有什么建议吗 XAML 视图模型 private static HtmlWebViewSource htmlSourceExplanation = new HtmlWebViewSource(); private ExtendedWebView _en; public ExtendedWebVi
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的回答完美地描述了如何做到这一点:
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;
};
}