GroupedObservableCollection icon indicating copy to clipboard operation
GroupedObservableCollection copied to clipboard

Error on comiling

Open Weasy666 opened this issue 8 years ago • 5 comments

Hi Mike,

i tried to implement and use your GroupedObservableCollection, but on compiling i got the following error Cannot determine the item type of collection type 'MangaReader_MVVM.Utils.GroupedObservableCollection'2[System.char,MangaReader_MVVM.Models.Manga]' because it has more than one Add method or ICollection<T> implementation. To make this collection type usable in XAML, add a public Add(object) method, implement System.Collections.IList or a single System.Collections.Generic.ICollection<T>. and i don't know where this other Add method should be. I didn't change anything of your code, just used it...so...do you maybe have an idea?

Weasy666 avatar Feb 10 '17 15:02 Weasy666

It sounds like you're embedding a GroupedObservableCollection directly in XAML, rather than binding one to a CollectionViewSource? Could you post the XAML that's giving the error?

mikegoatly avatar Feb 10 '17 16:02 mikegoatly

Hm...actually i tried to add it from code Behind

//Favorites is an ObservableCollection<Manga>
public GroupedObservableCollection<char, Manga> FavoritesGroups = new GroupedObservableCollection<char, Manga>(m => m.Title[0], Favorites);

private CollectionViewSource _favoritesCVS;
public CollectionViewSource FavoritesCVS
{
            get { return _favoritesCVS = _favoritesCVS ?? new CollectionViewSource() { IsSourceGrouped = true, Source = FavoritesGroups }; }
            set { Set(ref _favoritesCVS, value); }
}

in XAML i'm Binding it like this

<GridView x:Name="ZoomedInGridView"
                 ItemsSource="{x:Bind ViewModel.FavoritsCVS.View, Mode=OneWay}"
   ...more stuff... >
    <GridView.GroupStyle>
        <GroupStyle HidesIfEmpty="True">
            <GroupStyle.HeaderTemplate>
                <DataTemplate x:DataType="utils:Grouping">
                    <TextBlock Text="{x:Bind Key}" Margin="0,0,0,-10"
                                               Style="{ThemeResource SubheaderTextBlockStyle}"
                                               Foreground="{ThemeResource SystemControlHighlightAccentBrush}"/>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </GridView.GroupStyle>
</GridView>

I hope this helps. Do you also need the "Manga"-Model?

Weasy666 avatar Feb 10 '17 16:02 Weasy666

Hi, sorry for the delay - it looks like you're binding your ListView to ViewModel.FavoritsCVS.View - I think you should be binding it to the CollectionViewSource itself, e.g. ViewModel.FavoritsCVS.

Does that help?

mikegoatly avatar Feb 16 '17 08:02 mikegoatly

Got it working, thank you for the help. I think the problem was some kind of build artifact in the build folder.

Weasy666 avatar Feb 19 '17 19:02 Weasy666

ok, i was wrong. it's still there. when i get the GroupedObservableCollection from a Helper/Service as a Property and use that Property as a Source for the CVS i get the error. The same code as above:

public GroupedObservableCollection<char, Manga> FavoritesGroups { get { return _library.Favorites; } }

private CollectionViewSource _favoritesCVS;
public CollectionViewSource FavoritesCVS
{
            get { return _favoritesCVS = _favoritesCVS ?? new CollectionViewSource() { IsSourceGrouped = true, Source = FavoritesGroups }; }
            set { Set(ref _favoritesCVS, value); }
}

when i change the code like this

private CollectionViewSource _favoritesCVS;
public CollectionViewSource FavoritesCVS
{
            get { return _favoritesCVS = _favoritesCVS ?? new CollectionViewSource() { IsSourceGrouped = true, Source = new GroupedObservableCollection<char,Manga>(m => m.Title[0], Favorites) }; }
            set { Set(ref _favoritesCVS, value); }
}
//Favorites is an ObservableCollection<Manga>

it works. Do you have any idea why that is?

Weasy666 avatar Feb 22 '17 09:02 Weasy666