我尝试在 XAML 中使用 CollectionViewSource
以获得分组的 ListView
。
CSV:
<CollectionViewSource x:Key="MyViewSource"
IsSourceGrouped="True"
Source="{Binding MyItems, Mode=OneWay}" />
还有我的 DataTemplate
,我将其提供给我用于“缩小” View 的 GridView
上的 ItemTemplate
属性:
<DataTemplate x:Key="JumpTemplate"
x:DataType="data:ICollectionViewGroup">
<TextBlock FontSize="32"
FontWeight="SemiLight"
Text="{x:Bind ((linq:IGrouping)Group).Key}" />
</DataTemplate>
根据documentation这应该将该项目转换为 IGrouping
对象,然后该对象使我能够访问 Key
属性。但是,我不断收到错误
Invalid binding path '((linq:IGrouping)Group).Key' : Type 'linq:IGrouping' can't be found.
我已经非常明确地定义了它:
xmlns:data="using:Windows.UI.Xaml.Data"
xmlns:linq="using:System.Linq"
我知道这不是拼写错误或其他问题,因为 linq:IGrouping
上的 Go toDefinition
工作得很好。
是否有某些类型不允许使用或其他什么?
我使用的是 Windows 10 build 16257.1,使用 VS 2017 和 SDK Preview 16257。
最佳答案
错误信息正确:
Type 'linq:IGrouping' can't be found.
没有IGrouping
在 LINQ 中输入,但是有一个 IGrouping<out TKey, out TElement>
类型这不是同一件事。这样的转换在 C# 中也会失败。
XAML
不允许指定泛型类型参数,所以我认为您只能使用普通绑定(bind):Text="{Binding Key}"
关于linq - x :Bind type can't be found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45818719/