The GridView in Windows 8 uses (ii) and Datatemplateselector
Examples of what is described in this article are still used in the previous article, and there is no doubt that you can refer to the previous article.
One GroupStyle in the GridView control we can display the data in groups, and by controlling the GroupStyle of the GridView, we set up Groupstyle.headertemplate and Groupstyle.panel respectively. The following code:
<GridView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate>
<DataTemplate> <grid margin= "1,0,0,6" >
<button automationproperties.name= "group name" Content= "{Binding grouptitle}"/> </Grid> </datatemp
Late> </GroupStyle.HeaderTemplate> <GroupStyle.Panel> <ItemsPanelTemplate> <variablesizedwrapgrid orientation= "Vertical" margin=
"0,0,50,0"/> </ItemsPanelTemplate> </GroupStyle.Panel> </GroupStyle> </gridview.groupstyle>
Two datatemplateselector between different groups we would like to use a different style to display, where we can inherit rewrite Datatemplateselector class writing and select the corresponding style template based on the background data to render.
On the basis of previous code we need to do the following:
1. Writing a class inherits from Datatemplateselector
public class Templateselector:datatemplateselector {///<summary>///the first type of text display template///
</summary> public DataTemplate textboxtemplate {get; set;} <summary>///The second kind of picture is the main display template///</summary> public datatemplate imagetemplate {get; Set ///<summary>///Core method: Returns to the foreground different style templates///</summary>///<param n based on different data source types Ame= "Item" ></param>///<param name= "container" ></param>///<returns></retu
rns> protected override DataTemplate Selecttemplatecore (object item, DependencyObject container) {
Datamodel model = Item as Datamodel; String typeName = model.
Mainmodel.name; if (TypeName = = typeof (TextBox).
Name)//Returns the foreground style template {return textboxtemplate, according to the data display mode set by the data source; if (TypeName = = typeof (Image).
Name) { return imagetemplate;
return null; }
}