WPF C# Treeview with dynamic list from database -
i want use treeview show question , answer. pull list of questions answered , if have been answered in past show answer question. each answer either list in combobox or straight text. need pull correct template answer. have stored in database id of 1 of templates answer should pull. have never used before not sure how. if there better way too.
<src:uefusercontrol x:class="empcoverage.workobjects.controls.grwoinvestigatorquestions" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:party="clr-namespace:party_info.classes;assembly=partyinfo" xmlns:src="clr-namespace:oic.infrastructure.classes;assembly=oic.infrastructure" xmlns:oic="clr-namespace:empcoverage.classes.general_referral" width="auto" height="auto"> <usercontrol.resources> <style x:key="{x:type textbox}" targettype="textbox" basedon="{staticresource {x:type textbox}}"> <setter property="height" value="auto" /> <setter property="minwidth" value="100"/> <setter property="charactercasing" value="upper"/> </style> <style x:key="{x:type label}" targettype="label" basedon="{staticresource {x:type label}}"> <setter property="horizontalalignment" value="right"/> </style> <hierarchicaldatatemplate x:name="hdttextbox" datatype="{x:type oic:mytemplateselector}" itemssource="{binding path=answers}"> <stackpanel> <label content="{binding path=question}" grid.row="0" grid.column="1" visibility="hidden"/> <textblock name="txtanswer" text="{binding path=answer}" grid.row="1" grid.column="0" textwrapping="wrap" /> </stackpanel> </hierarchicaldatatemplate> <hierarchicaldatatemplate x:name="hdtcombobox" datatype="{x:type oic:mytemplateselector}" itemssource="{binding path=answers}"> <stackpanel> <label content="{binding path=question}" grid.row="0" grid.column="1" visibility="hidden"/> <combobox name="cboanswer" grid.row="1" grid.column="0" width="auto" minwidth="200" itemssource="{binding answers}" displaymemberpath="answer" selectedvalue="{binding path=answer}" /> </stackpanel> </hierarchicaldatatemplate> </usercontrol.resources> <grid width="auto" height="auto" name="gdgeneralreview"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="auto"/> <rowdefinition height="40"/> <rowdefinition height="auto"/> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="auto"/> <columndefinition width="auto"/> </grid.columndefinitions> <treeview name="tvgeneralreferral" grid.row="0" grid.column="0" selecteditemchanged="tvgeneralreferral_selecteditemchanged" > </treeview> <button grid.row="4" grid.column="0" grid.columnspan="2" name="btnsave" height="30" width="60" content="save" verticalalignment="center" click="btnsave_click" /> </grid>
you can define itemtemplateselector return proper template based on logic provide.
<window.resources> <vm:mytemplateselector x:key="mytemplateselector" /> </window.resources> <treeview itemtemplateselector={staticresource mytemplateselector} />
a sample selector
public class mytemplateselector : datatemplateselector { public override datatemplate selecttemplate(object item, dependencyobject container) { if (item string) return ((frameworkelement) container).findresource("texttemplate") datatemplate; else return ((frameworkelement)) container).findresource("enumtemplate") datatemplate; } }
Comments
Post a Comment