wpf - Cannot set Foreground Color to a TreeView DataTemplate TextBlock (MVVM) -


i bind treenode item list tree view. not able bind datatemplate textblock foreground color.

initally tought binding problem, tried give color manually, namely foreground="red" figured not change text color.

xaml:

 <treeview  itemssource="{binding treeviewnodesplccode}" >          <treeview.itemtemplate>               <datatemplate>                   <grid>                      <textblock text="{binding name}" foreground="{binding path=machineobject.color}"/>                      </grid>                </datatemplate>           </treeview.itemtemplate>    </treeview> 

code:

treeviewnodesplccode=new observablecollection<treenode>()   public class treenode: treeviewitem     {         public string name{ get; set; }         public machine machineobject { get; set; }     }   public class machine     {         public int32 id { get; set; }         public brush color { get; set; }     } 

when try code, following output in visual studio:

itemtemplate , itemtemplateselector ignored items of itemscontrol's container type; type='treenode'

this means adding in treeview items can added directly without datatemplate.

datatemplate made visualize data objects (i.e. business objects). treeviewitem have datatemplate.

to solve issue, remove inheritance treeviewitem class treenode:

public class treenode     {         public string name{ get; set; }         public machine machineobject { get; set; }     } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -