Getting Started with Windows 8 Development (20) GridView Usage in Windows 8 (ii)

Source: Internet
Author: User

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; }
    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.