C# WPF Binding to DataBase -
hei all. if not clear please tell
i have datagrid , treeview. have loaded data base entity data model , tables. 1 of these tables "relation" should show datagrid. (relation table) column depend of other tables system,model,function , device. in data grid should 4 columns contain names of these system,model,function , device. (the picture 1 should be)
problem in how show. datasource don't work well... see picture 2.
<grid datacontext="{staticresource relationsviewsource}"> <datagrid autogeneratecolumns="true" name="gridinventory" horizontalcontentalignment="right" margin="255,12,12,128" itemssource="{binding}" /> <stackpanel height="391" horizontalalignment="left" margin="10,10,0,0" name="stackpanel1" verticalalignment="top" width="239" datacontext="{staticresource systemsviewsource}" > <treeview height="391" name="treeview1" width="239" verticalcontentalignment="top" horizontalalignment="left" verticalalignment="top" itemssource="{binding}" /> </stackpanel> </grid>
picture 1:
picture2:
you binding both treeview
, of datagrid
columns object, not telling wpf how draw object. when wpf doesn't know how draw object
, default draws using textblock
text
bound object's .tostring()
you need set itemtemplate
tell wpf how draw individual objects, such this:
<treeview.itemtemplate> <datatemplate> <textblock text="{binding name}" /> </datatemplate> </treeview.itemtemplate>
you use implicit datatemplate
tell wpf how draw specific objects. datatemplate specifies datatype
without key
, , wpf use anytime tries render object of specified type.
if want avoid removing autogeneratecolumns="true"
, manually specifying datagrid's columns, method use.
<datagrid.resources> <datatemplate datatype="{x:type local:device}"> <textblock text="{binding name}" /> </datatemplate> </datagrid.resources>
Comments
Post a Comment