![](/img/trans.png)
[英]Why can't a DataTemplate bind to an interface when that DataTemplate was explicitly returned from a DataTemplateSelector?
[英]Datatemplate not showing in ListView after being returned by DataTemplateSelector
我正在构建一个Xamarin Forms应用程序,在其中一个屏幕上,我使用ObservableCollection填充ListView。 使用DataTemplateSelector类选择ItemTemplate,该类在调试期间被命中并返回DataTemplate。 但是,当打开时,我没有看到表单上显示的模板。 我目前正在使用UWP接口进行调试。
到目前为止,我已经尝试添加一个ListView,它有一个简单的标签项模板,它似乎也不起作用。 我看到Visual Tree中有一个列表视图项,尽管它只包含一个包含CellControl的ListViewItemPresenter。
我绑定的属性是:
public Generators.Parameter.ConfigurationList Parameters { get; }
ConfigurationList继承ObservableCollection:
public class ConfigurationList : ObservableCollection<Configuration>
显示简单ListView的xaml是:
<ListView ItemsSource="{Binding Parameters}">
<ListView.ItemTemplate>
<DataTemplate>
<Label Text="Test" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
完整的源代码可以在github上找到TheRandomizer.Mobile
在提交我的问题后,我立即想出来,但我想我会留下它以防万一其他人遇到这个问题。 DataTemplate需要:
<ListView ItemsSource="{Binding Parameters}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="Test" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.