c# - Wpf TreeView get data item used to bind template -
c# - Wpf TreeView get data item used to bind template -
i binding treeview custom template. have button in template , when user clicks need find out info item used bind specific template instance against.
so if bind treeview ilist need mytreeitem that provided info specific template instance.
my code looks this:
<treeview grid.column="1" horizontalalignment="left" height="268" margin="10,41,0,0" verticalalignment="top" width="197" x:name="trviewcodetree"> <treeview.itemtemplate> <hierarchicaldatatemplate itemssource="{binding children}" datatype="roslyndemos:trviewcodetreeitem"> <wrappanel> <label content="node type:" horizontalalignment="left" margin="10,10,0,0" verticalalignment="top" height="26" width="70"/> <textblock text="{binding nodetype}" margin="10,10,0,0"></textblock> <label content="node position" margin="10,10,0,0" verticalalignment="top" height="26" width="80"/> <textblock text="{binding position}" margin="10,10,0,0"></textblock> <label content="node length" margin="10,10,0,0" verticalalignment="top" height="26" width="75"/> <textblock text="{binding length}" margin="10,10,0,0"></textblock> <button x:name="btnselect" click="btnselect_onclick"></button> </wrappanel> </hierarchicaldatatemplate> </treeview.itemtemplate>
private void btnselect_onclick(object sender, routedeventargs e) { var button = sender button; var dataitem = button.datacontext [your dataitem class here]; dataitem.[dostuffhere](); }
c# wpf xaml treeview
Comments
Post a Comment