How to modify silverlight combobox data display -


i have combobox defined follows:

<combobox x:name="cbodept" grid.row="0" margin="8,8,8,8" horizontalalignment="left" verticalalignment="top" width="120"                    itemssource="{binding source={staticresource cvscategories}}">             <combobox.itemtemplate>                 <datatemplate>                     <stackpanel orientation="vertical" width="auto" height="auto">                         <sdk:label content="{binding categoryid}" height="20" />                         <sdk:label content="{binding categoryname}" height="20" />                     </stackpanel>                 </datatemplate>             </combobox.itemtemplate>         </combobox> 

it works fine. however, once select item in list, want different template applied combobox selected item being shown user (the item shown after disappearance of popup). in above case, want categoryname displayed in combobox once select respective item.

can let me know on how achieve this?

thanks

what need create resourcedictionary containing few defined templates yourself. in below, comboboxtemplateone , comboboxteplatetwo user controls set out display combobox in manor want.

   <usercontrol.resources>         <resourcedictionary>           <datatemplate x:key="templateone">                <local:comboboxtemplateone />             </datatemplate>           <datatemplate x:key="templatetwo">                <local:comboboxtemplatetwo />             </datatemplate>         </resourcedictionary>    </usercontrol.resources> 

you need create own class inherits contentcontrol "datatemplateselector", overriding oncontentchanged

  protected overrides sub oncontentchanged(byval oldcontent object, byval newcontent object)     mybase.oncontentchanged(oldcontent, newcontent)      me.contenttemplate = selecttemplate(newcontent, me)    end sub 

you need create class inherits above datatemplateselector overrides selecttemplate ("templateselectorclass"), return datatemplate defined above ("templateone" or "templatetwo"). in derived class, need define property each of templates have

public property comboboxtemplateone datatemplate 

then head xaml , n blow xaml

 <local:templateselectorclass  comboboxtemplateone="{staticresource templateone}"  content="{binding path=activeworkspace}> 

this should work, doing same work setting "datatemplate" property in wpf (which doesn't exist in silverlight) realise there fair few steps here , quite fiddly, there. questions shout.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -