Seleccione DataTempate en un GridView según el grupo
Frecuentes
Visto 158 veces
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
clase
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).
yo vi uno parecido pregunta , but I have the same problems.
Is there any way to select data template by group?
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# windows-runtime datatemplate or haz tu propia pregunta.
Having a favorites class that inherits from ItemType is not an option? - Jeff Brand
I deserialize ItemType from JSON, so I've just put in into the wrapper class, wich holds a Group and an ItemType. - Anton Sizikov