Search code examples
linqxamluwpcollectionviewsourcexbind

x:Bind type can't be found


I'm attempting to use a CollectionViewSource in my XAML in order to have a grouped ListView.

The CSV:

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

And my DataTemplate which I provide to the ItemTemplate property on my GridView which I'm using for the "zoomed out" view:

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

According to the documentation this should cast the item to an IGrouping object, which then gives me access to the Key property. However, I keep getting an error

Invalid binding path '((linq:IGrouping)Group).Key' : Type 'linq:IGrouping' can't be found.

I've very clearly defined it:

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

I know it's not a typo or something because Go to definition on the linq:IGrouping works just fine.

Are there certain types which aren't allowed to be used or something?

I'm on Windows 10 build 16257.1, using VS 2017 and SDK Preview 16257.


Solution

  • The error message is correct:

    Type 'linq:IGrouping' can't be found.

    There is no IGrouping type in LINQ, there is however a IGrouping<out TKey, out TElement> type which is not the same thing. Such a cast will fail in C# also.

    XAML doesn't allow to specify generic type parameters so I think you are stuck with a normal binding: Text="{Binding Key}"