c# - Unselecting databound objects in a WPF treeview -
c# - Unselecting databound objects in a WPF treeview -
i'm working on wpf application have 2 treeviews. both have collection of viewmodel objects itemssource. i'm trying create when user selects item in 1 treeview, other's selection changed null.
however, noticed actual items in treeview of type somethingviewmodel , not treeviewitem. means have no isselected property. i've tried adding isselected property viewmodel objects , binding property treeviewitem template i'm using, doesn't seem work.
xaml:
<treeview x:name="trvmaterials" selecteditemchanged="trvmaterials_selecteditemchanged" itemssource="{binding materiallistviewmodel.materialviewmodels}"> <treeview.itemtemplate> <hierarchicaldatatemplate itemssource="{binding materialvariants}"> <treeviewitem header="{binding internalname, mode=oneway}" isselected="{binding isselected}"></treeviewitem> </hierarchicaldatatemplate> </treeview.itemtemplate> </treeview>
c#:
public bool isselected { { homecoming isselected; } set { isselected = value; raisepropertychanged("isselected"); } }
how can functionality work? please maintain in mind i'm new wpf , mvvm.
thanks!
don't bind isselected did. add together itemcontainerstyle
below:
<treeview x:name="trvmaterials" selecteditemchanged="trvmaterials_selecteditemchanged" itemssource="{binding materiallistviewmodel.materialviewmodels}"> <treeview.itemcontainerstyle> <style targettype="treeviewitem"> <setter property="isselected" value="{binding isselected, mode=twoway}"/> </style> </treeview.itemcontainerstyle> <treeview.itemtemplate> <hierarchicaldatatemplate itemssource="{binding materialvariants}"> <textblock text="{binding internalname, mode=oneway}"></textblock > </hierarchicaldatatemplate> </treeview.itemtemplate> </treeview>
c# wpf xaml mvvm treeview
Comments
Post a Comment