Listview 如何在xamarin表单的列表视图中使用web视图
我想使用HTML源上的MVVM数据绑定在列表视图中显示web视图 请尝试以下代码: 对于您的xaml文件:Listview 如何在xamarin表单的列表视图中使用web视图,listview,xamarin.forms,webview,Listview,Xamarin.forms,Webview,我想使用HTML源上的MVVM数据绑定在列表视图中显示web视图 请尝试以下代码: 对于您的xaml文件: <ContentPage.Resources> <ResourceDictionary> <local:HtmlSourceConverter x:Key="HtmlSourceConverter" /> </ResourceDictionary> </ContentPage.Resource
<ContentPage.Resources>
<ResourceDictionary>
<local:HtmlSourceConverter x:Key="HtmlSourceConverter" />
</ResourceDictionary>
</ContentPage.Resources>
...
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<WebView Source="{Binding MyHtml, Converter={StaticResource HtmlSourceConverter}}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
模型
视图模型
private IList<MyWebSite> _list;
public IList<MyWebSite> List
{
get{
return _list;
}
set{
_list = value;
}
}
...
public MainPageModel()
{
List = new List<MyWebSite>(){
new MyWebSite(){
MyHtml = "<html><body><h1>Xamarin.Forms</h1><p>Welcome to WebView 1</p></body></html>"
},
...
...
}
}
私有IList\u列表;
公共IList列表
{
得到{
返回列表;
}
设置{
_列表=值;
}
}
...
公共主页模型()
{
列表=新列表(){
新MyWebSite(){
MyHtml=“Xamarin.Forms欢迎使用WebView 1”
},
...
...
}
}
在ListView模板中放置一个WebView控件。你试过这个吗?没有什么特别复杂的。
public class MyWebSite
{
public string MyHtml { get; set; }
}
private IList<MyWebSite> _list;
public IList<MyWebSite> List
{
get{
return _list;
}
set{
_list = value;
}
}
...
public MainPageModel()
{
List = new List<MyWebSite>(){
new MyWebSite(){
MyHtml = "<html><body><h1>Xamarin.Forms</h1><p>Welcome to WebView 1</p></body></html>"
},
...
...
}
}