linq - x :Bind type can't be found

标签 linq xaml uwp collectionviewsource xbind

我尝试在 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/

相关文章:

WPF RibbonWindow 不显示 Grip 以调整窗口大小

c# - 在 WPF 中将鼠标光标悬停在禁用按钮上时将鼠标光标更改为 "stop"指针

uwp - 如何避免 UWP 应用程序中的重复条目构建错误?

xml - 如何使用 Linq to Xml 克隆 xml 元素

c# - 为什么查询结果少了一个字符?

wpf - caliburn.micro 如何为 View 模型运行时加载和绑定(bind) View

azure - 使用客户的 Active Directory(Azure 或 ADFS)对 UWP 客户端和 .Net Core Web 应用程序进行身份验证

c# - 警告 : MapServiceToken not specified

c# - LINQ 命名标准 - Lambda 表达式

c# - Entity Framework ,根据包含从相关表中获取元素