c# - apply a template to a column of datagrid -


i'm using mvvm , want apply template specific column of datagrid.

i create machine class have name, costs, properties.

i create operation class have name porperty, executivemachine property (type : machine) when use itemssource display list of opertations, see path of machines whereas want display name. added datagridtemplatecolumn now, have machine column twice (one correct, , other incorrect)

actually code :

<datagrid itemssource="{binding path=operations}" name="datagridoperation" width="auto" height="auto" margin="10" horizontalcontentalignment="center" selectionmode="single" mincolumnwidth="80" canuseraddrows="false" canuserdeleterows="false" rowbackground="dimgray" alternatingrowbackground="#ff3e3e3e" alternationcount="1" isreadonly="true" selectionchanged="updateoperationcombobox">     <datagrid.columns>         <datagridtemplatecolumn header="machine" canusersort="true">             <datagridtemplatecolumn.celltemplate>                 <datatemplate>                     <label content="{binding path=executivemachine.name}"/>                 </datatemplate>             </datagridtemplatecolumn.celltemplate>         </datagridtemplatecolumn>     </datagrid.columns>   </datagrid> 

my first idea add manually datagridcolumns. tried when have twice columns , if delete itemssource property of datagrid have once 3 columns become empty. if idea good, how can bind itemssource ?

if want add columns manually need switch off autogeneratecolumns against datagrid

<datagrid      itemssource="{binding path=operations}"      name="datagridoperation"     ...     autogeneratecolumns="false"> 

edit

to manually define sorting path datagridcolumn can specify datagridcolumn.sortmemberpath

<datagridtemplatecolumn header="machine" canusersort="true" sortmemberpath="sortpropertyname"> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -