i working on developing windows store app using c#/xaml. have experience in ios , extent android app development, not yet comfortable c#/xaml world.
here issue in gridview based page (based on nice template vs2012 generates).
i have gridview , collection bound data retrieved network , works fine. want change grid item depending on data. example: have files , folders show using different grid view items.
my question: how use different datatemplate itemtemplate depending on data? example, "folders", have 1 textblock vertically centered , file, have 2 textblocks , visually different.
am going right path or should doing different?
the xaml portion is
<gridview x:name="itemgridview" automationproperties.automationid="itemgridview" automationproperties.name="grouped items" grid.rowspan="3" padding="116,137,40,46" itemssource="{binding source={staticresource groupeditemsviewsource}}" itemtemplate="{staticresource fileentriestemplate}" itemclick="itemview_itemclick" isitemclickenabled="true" selectionmode="none" isswipeenabled="false">
the template is
<datatemplate x:key="fileentriestemplate"> <grid horizontalalignment="left" width="400" height="80" background="beige"> <grid.columndefinitions> <columndefinition width="80"/> <columndefinition width="*"/> </grid.columndefinitions> <image source="{binding image}" stretch="uniform" grid.column="0" margin="10,0,0,0" automationproperties.name="{binding title}"/> <stackpanel orientation="vertical" grid.column="1" background="transparent"> <textblock text="{binding title}" foreground="black" style="{staticresource largetitletextstyle}" margin="20,20,10,0"/> <textblock text="{binding subtitle}" foreground="gray" style="{staticresource captiontextstyle}" textwrapping="nowrap" margin="20,10,0,30"/> </stackpanel> </grid>
gridview exposes through itemtemplateselector property class can create inherits datatemplateselector. example have gridview has issues , repositories bound , want use different data templates each.
my data template selector looks like:
public class issuesummarytemplateselector : datatemplateselector { protected override datatemplate selecttemplatecore(object item, dependencyobject container) { return item issuegroupviewmodel ? issuetemplate : repositorytemplate; } public datatemplate repositorytemplate { get; set; } public datatemplate issuetemplate { get; set; } }
i declare selector resource in xaml assigning 2 templates want use repository , issues.
<selectors:issuesummarytemplateselector x:key="issuesummaryselector" issuetemplate="{staticresource issuegridzoomedouttemplate}" repositorytemplate="{staticresource issuegridrepositoryzoomedouttemplate}"/>
you can use on gridview.
<gridview itemtemplateselector="{staticresource issuesummaryselector}" />
Comments
Post a Comment