c# - How to change GridView.ItemTemplate while app is running? -
in app have page gridview , combobox. want change gridview.itemtemplate property according selected item in combobox. how should implement it?
btw, know this question, quite old , not "best practice". (how visibility/invisibility of ui control affects cpu/gpu load?)
my gridview:
<gridview x:name="gridviewmain" grid.row="1" selectionmode="none" isitemclickenabled="true" itemssource="{binding currentlist}" itemtemplate="{staticresource gridviewmainitemtemplate}" loaded="gridviewmain_loaded" layoutupdated="gridviewmain_layoutupdated"> <interactivity:interaction.behaviors> <core:eventtriggerbehavior eventname="itemclick"> <core:callmethodaction methodname="gridviewclick" targetobject="{binding mode=oneway}" /> </core:eventtriggerbehavior> </interactivity:interaction.behaviors> </gridview>
one of templates:
<datatemplate x:key="gridviewmainitemtemplate"> <grid x:name="gridatemplate" width="185" height="288"> <image x:name="imgatemplate" source="{binding image_url}" stretch="uniformtofill" horizontalalignment="center" verticalalignment="center" /> <grid background="{themeresource listviewitemoverlaybackgroundthemebrush}" verticalalignment="bottom"> <grid.rowdefinitions> <rowdefinition /> <rowdefinition /> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition /> <columndefinition /> </grid.columndefinitions> <textblock x:name="textblocktitle" text="{binding title}" textwrapping="wrap" style="{staticresource bodytextblockstyle}" margin="5,0,0,0" grid.row="0" grid.column="0" grid.columnspan="2" foreground="white" fontweight="bold" maxheight="50" /> <textblock x:name="textblocktype" textwrapping="wrap" style="{staticresource bodytextblockstyle}" margin="5,0,0,0" grid.column="0" grid.row="1" foreground="white" text="{binding type}" fontweight="bold" /> <stackpanel grid.row="1" grid.column="1" orientation="horizontal"> <textblock x:name="textblockprogressl" textwrapping="wrap" style="{staticresource bodytextblockstyle}" fontweight="bold" foreground="white" text="progress:" /> <textblock x:name="textblockprogressv" textwrapping="wrap" style="{staticresource bodytextblockstyle}" fontweight="bold" foreground="white" text="{binding watched_episodes}" margin="10,0,0,10" /> </stackpanel> </grid> </grid> </datatemplate>
sure can this! in xaml can anything. cannot change template on fly without re-rendering. remember, telling printer use card stock. obey. if change setting use notebook paper, obey that, too. have print again since has printed on card stock.
there few ways re-render gridview. 1 way navigate away page , navigate back. that's not ideal sounding in scenario. odds are, in scenario, need reset observablecollection using. this:
void reset<t>(observablecollection<t> collection) { var original = collection.toarray(); collection.clear(); foreach (var item in original) collection.add(item); }
best of luck!
Comments
Post a Comment