c# - WPF Treeview HierarchicalDataTemplate ItemTemplateSelector -


i trying create simple 2 level treeview in wpf (mvvm approach). first level have standard datatemplate, second level want use template selector can change appearance of each item based on 1 of properties.

below treeview xaml

<treeview itemssource={binding lista}>       <treeview.itemtemplate>        <hierarchicaldatatemplate itemssource="{binding listb}" itemtemplateselector={staticresource templateselector}>          <textblock text={binding name}/>       </hierarchicaldatatemplate>    </treeview.itemtemplate> </treeview> 

my first level is

<textblock text={binding name}/>  

will display name

for second level templateselector returning datatemplate like

<datatemplate x:key="somekey"> <stackpanel orientation="horizontal"> <viewbox> ----- </viewbox> <textblock text={binding name}/> </stackpanel> </datatemplate> 

but see second level second level viewmodel name. double checked template selector , returning correct data template not getting displayed.

can please point me in right direction?

edit -- added more code per request

this template selector

public class datafieldsdatatemplateselector : datatemplateselector { public datatemplate alphatemplate { get; set; } public ------ public ------ public datafieldsdatatemplateselector() { //this getting template resourcedictionary alphatemplate = (datatemplate)ddictionary["alphatemplate"]; } public override datatemplate selecttemplate(object item,dependencyobject container)         { //somecode return alphatemplate; } } 

my template alphatemplate in dictionary is

<datatemplate x:key="alphatemplate">              <grid >                 <grid.columndefinitions>                     <columndefinition width="15"/>                     <columndefinition width="*"/>                 </grid.columndefinitions>                 <viewbox  ishittestvisible="false">                      <path data="m0,0l56.622002,0 56.622002,14.471 35.715,14.471 35.715,64 20.715,64 20.715,14.471 0,14.471z" stretch="uniform" fill="{dynamicresource buttonforegroundnormal}" verticalalignment="center" width="15" height="15" margin="0,0,0,0" rendertransformorigin="0.5,0.5">                         <path.rendertransform>                             <transformgroup>                                 <transformgroup.children>                                     <rotatetransform angle="0" />                                     <scaletransform scalex="1" scaley="1" />                                 </transformgroup.children>                             </transformgroup>                         </path.rendertransform>                     </path>                  </viewbox>                 <textblock text="{binding name}/>             </grid>     </datatemplate> 

my class typeb contains name(text) , datatype(text) fields if datatype alpha return alphatemplate in templateselector , on

i have action(dragdrop) on window adds items second level. , want template selector should pick correct datatemplate dropped item based on datatype

my main viewmodel contains icollectionview of typea objects , each typea viewmodel contains icollectionview of typeb viewmodels.

let me know if need anything

i dont know wrong this require debug code, wanted achieve can done defining default datatemplate typeb , switching content depending on binding this:

<datatemplate datatype="{x:type typeb}">             <contentcontrol>                 <contentcontrol.style>                     <style targettype="{x:type contentcontrol}">                         <setter property="contenttemplate">                             <setter.value>                                 defaulttemplatehere item                             </setter.value>                         </setter>                         <style.triggers>                             <datatrigger binding="{binding xyz}" value="true">                                 <setter property="contenttemplate">                                     <setter.value>                                         differenttemplate item                                     </setter.value>                                 </setter>                             </datatrigger>                         </style.triggers>                     </style>                 </contentcontrol.style>             </contentcontrol>          </datatemplate> 

thanks


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -