问题描述
好的,这应该很简单,但我卡住了。
我正在升级一个旧的 .Net Xamarin 项目,我想做的一件事是将 x:DataType 标记添加到 XAML 文件,以便它可以验证和自动完成所有绑定。例如
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:MyProject.PageModels.Info"
xmlns:models="clr-namespace:MyProject.Models"
x:DataType="vm:InfoViewModel"
x:Class="MyProject.Pages.Info.InfoPage"
Title="PageTitle">
到目前为止一切都很好,但是这个特定的页面显示了一个分组的记录列表,定义为:
public List<IGrouping<string,LocalDocument>> GroupedDocs { get; set; }
现在编译器抱怨,因为我没有为 ListView.GroupHeaderTemplate 设置有效的 DataType(因为模板中的绑定在 ViewModel 中不存在)......我不知道该分配给它什么,因为 x:DataType 似乎不支持接口(更不用说接口 + 泛型了)。
<ListView ItemsSource="{Binding GroupedDocs}" IsGroupingEnabled="true"
Style="{StaticResource groupedList}" ItemTappedCommand="{Binding DocumentTappedCommand}">
<ListView.GroupHeaderTemplate>
<DataTemplate x:DataType="????"> <!-- <<<<< What to put here? -->
<ViewCell Height="34">
<StackLayout Style="{StaticResource groupHeader}">
<Label Text="{Binding Key}"
Style="{StaticResource groupHeaderText}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:LocalDocument">
<!-- (....) -->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我应该指定什么而不是 ????在前面的代码示例中?
作为一种变通方法,我创建了一个实现
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)