xaml - WPF TreeView Nodes becomes unselectable after adding children nodes -
i have huge issue wpf treeview. have setup tree similar this.
<treeview datacontext="{binding projects}"> <style targettype="treeviewitem"> <setter property="isexpanded" value="true" /> </style> <treeview.resources> <hierarchicaldatatemplate x:key="loadtemplate"> <grid> <textblock text="{binding name}" /> </grid> </hierarchicaldatatemplate> <hierarchicaldatatemplate x:key="steptemplate" itemssource="{binding loads}" itemtemplate="{staticresource loadtemplate}"> <grid> <textblock text="{binding name}" /> </grid> </hierarchicaldatatemplate> <hierarchicaldatatemplate x:key="projecttemplate" itemssource="{binding steps}" itemtemplate="{staticresource steptemplate}"> <grid> <textblock text="{binding name}" /> </grid> </hierarchicaldatatemplate> </treeview.resources> <treeviewitem header="project workspace" itemssource="{binding}" isexpanded="true" itemtemplate="{staticresource projecttemplate}" /> </treeview>
the treeview bound dependencyproperty called projects observablecollection in code-behind file xaml. basic structure of classes tree bound follows structure of tree. project contains custom collection implements both inotifypropertychanged , icollectionchanged interfaces. collection accessible through property called steps , contains step objects. step class has instance of same custom collection accessable property called loads , contains load objects.
now when work object within projects, tree behaves correctly in nodes appear , dissappear , change correctly set of nested collections change. part, works should.
althought didn't show in xaml above, each of nodes above have own specific context menu added. 1 of options in context menu add object. instance, if right click on step node, have option add load node beneath it. adding load class loads property in step object cause node show in tree fine.
so instance code looks similar this:
projects[0].steps[0].loads.add(new load());
ok, here problem i've been trying figure out longest time now. after new node shows in tree, it's parent node no longer selectable. in given example, cannot select step node owns newly added load node. can still things doubleclick , rightclick , events fire, attepting single click left mouse button not cause step node selected or have focus. i've tried can think of , cannot life of me figure out why not.
now can click around on other nodes in tree , selecatable fine. , after doing so, node not allow being selected regains it's former functionality , once again able selected.
so happens add new node, shows , it's parent can't selected until select other part of treeview , fine again.
with no , nothing tried having worked, switched using telerik controls. after replacing default treeview radtreeview telerik, issues disappeared. i'd suggest if possible people avoid microsoft's built in wpf treeview control plagued countless issues , you'll spend great amounts of time trying deal them, rather developing application.
Comments
Post a Comment