0

I've got a few collections of items. All items has the same type:

public class ItemType 
{
   public string Name {get;set;}
}

Some of items are "favorites". They are the same, but I store them in a separate collection. I have a goup of items class:

public class ItemsGroup 
{
   public List<ItemType> Items {get;set;}
   public string Title {get;set;}
}

So, some items are in one group, and some items are in "favorites" group. (Title = "Favorives".

Also, I have a page with a <GridView>. I want to set different data tempates according to group. (BigItem and SmallItem for example). I can achieve that by adding an extra field to ItemType:

public enum GroupType { Fav, Other; }

public class ItemType
{
   public string Name {get;set;}
   public GroupType Type {get; set;}
}

and select data template in DataTemplateSelector class

    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
    {
        var x = item as ItemType;
        if(x != null)
        {
            if(x.Type == GroupType.Fav) return FavDataTemplate;
        }
        return DefaultDataTemplate;

    }

But I don't want to add extra fields to ItemType, because it's a shared class (wp7, winrt ect).

I saw a similar question , but I have the same problems.

Is there any way to select data template by group?

4

0 回答 0