【问题标题】:x:Bind type can't be foundx:找不到绑定类型
【发布时间】:2017-08-22 13:15:43
【问题描述】:

我正在尝试在我的 XAML 中使用 CollectionViewSource,以便将 ListView 分组。

CSV:

<CollectionViewSource x:Key="MyViewSource"
                      IsSourceGrouped="True"
                      Source="{Binding MyItems, Mode=OneWay}" />

还有我提供给GridView 上的ItemTemplate 属性的DataTemplate,用于“缩小”视图:

<DataTemplate x:Key="JumpTemplate"
              x:DataType="data:ICollectionViewGroup">
    <TextBlock FontSize="32"
               FontWeight="SemiLight"                       
               Text="{x:Bind ((linq:IGrouping)Group).Key}" />
</DataTemplate>

根据documentation,这应该将项目转换为IGrouping 对象,然后我可以访问Key 属性。但是,我不断收到错误

无效的绑定路径“((linq:IGrouping)Group).Key”:找不到类型“linq:IGrouping”。

我已经很清楚地定义了:

xmlns:data="using:Windows.UI.Xaml.Data"
xmlns:linq="using:System.Linq"

我知道这不是拼写错误或其他什么,因为 linq:IGrouping 上的 Go to definition 工作正常。

是否有某些类型是不允许使用的?

我在 Windows 10 build 16257.1 上,使用 VS 2017 和 SDK Preview 16257。

【问题讨论】:

    标签: linq xaml uwp collectionviewsource xbind


    【解决方案1】:

    错误信息正确:

    找不到类型“linq:IGrouping”。

    在 LINQ 中没有 IGrouping 类型,但是有一个 IGrouping&lt;out TKey, out TElement&gt; 类型,这不是一回事。这样的转换在 C# 中也会失败。

    XAML 不允许指定泛型类型参数,所以我认为您只能使用普通绑定:Text="{Binding Key}"

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多