【发布时间】:2020-05-14 09:15:14
【问题描述】:
我有 webView,我正在通过 ViewModel 绑定它,当我调试它时,我知道该值在那里但是我看不到它。我将它设置在视图的后面,所以我知道一切正常,但我无法从 ViewModel 显示它。有什么建议吗?
XAML
<controls:ExtendedWebView
x:Name="nameEng"
HeightRequest="150"
IsVisible="True"
Opacity="1"
Source="{Binding EN}" />
内容页面
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;
};
}
【问题讨论】:
-
我看到您在视图模型中将 ExtendedWebView 作为属性公开。这不是应该的样子。您基本上是将 WebView.Source(来自您的 XAML)设置为新的 WebView。我认为您应该公开 HtmlText 并将 Source 属性绑定到它。
-
你能告诉我怎么做吗?
标签: xamarin.forms