Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on comiling #1

Open
Weasy666 opened this issue Feb 10, 2017 · 5 comments
Open

Error on comiling #1

Weasy666 opened this issue Feb 10, 2017 · 5 comments

Comments

@Weasy666
Copy link

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?

@mikegoatly
Copy link
Owner

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?

@Weasy666
Copy link
Author

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?

@mikegoatly
Copy link
Owner

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?

@Weasy666
Copy link
Author

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

@Weasy666
Copy link
Author

Weasy666 commented Feb 22, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants