c# - Programmatically change ListBox DataTemplate -


hey guys wandering if can show me how programmatically change listboxdatatemplate. have datatemplate:

<datatemplate x:key="datatemplate1">         <grid toolkit:tilteffect.istiltenabled="true" d:designwidth="446" width="446" d:designheight="108" height="108">             <textblock textwrapping="nowrap" text="{binding accounttitle}" verticalalignment="top" width="456" horizontalalignment="left" height="40" fontfamily="segoe wp" fontsize="28" />             <textblock textwrapping="nowrap" text="{binding accountusername}" verticalalignment="top" width="456" margin="0,33,0,0" horizontalalignment="left" height="35" fontfamily="segoe wp" fontsize="24" />             <textblock textwrapping="nowrap" text="{binding accountwebsite}" verticalalignment="top" width="456" margin="0,61,0,0" horizontalalignment="left" height="35" fontfamily="segoe wp" fontsize="24" />             <textblock textwrapping="nowrap" text="{binding folderid}" verticalalignment="top" width="456" margin="0,96,0,-13" horizontalalignment="left" height="35" fontfamily="segoe wp" fontsize="24" opacity="0" visibility="collapsed" />             <textblock textwrapping="nowrap" text="{binding accountdate}" verticalalignment="top" margin="0,38,0,0" fontfamily="segoe wp" fontsize="20" textalignment="right" horizontalalignment="right" />         </grid> </datatemplate> 

now when user sets setting on settings page, listbox datatemplate must change this:

<datatemplate x:key="datatemplate1">         <grid toolkit:tilteffect.istiltenabled="true" d:designwidth="446" width="446" d:designheight="108" height="108">             <textblock textwrapping="nowrap" text="{binding accounttitle}" verticalalignment="top" width="456" horizontalalignment="left" height="40" fontfamily="segoe wp" fontsize="28" />             <textblock textwrapping="nowrap" text="{binding accountdate}" verticalalignment="top" margin="0,38,0,0" fontfamily="segoe wp" fontsize="20" textalignment="right" horizontalalignment="right" />         </grid> </datatemplate> 

is possble this? if please me. thanks!

one of many ways, define 2 datatemplates in page resources. can set listbox's itemtemplate 1 of 2 @ run-time :

mylistbox.itemtemplate = (datatemplate)findresource("datatemplate2");  

update :

since, findresource() function not available in windows phone page, , confirmed op 1 works him, use following instead of above code :

mylistbox.itemtemplate = (datatemplate)this.resources["datatemplate2"];  

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -