datagrid - How add a global "IsReadOnly" style to all DataGridTextColumns -


i have resourcedictionary file wpf application, pretty adds every style possibly want throughout of application's datagrids.

except one.

how can add global "isreadonly" setter, of datagrid's datagridtextcolumn columns ?

basically, use few datagrids, , if want display read-only data in particular column, i'll display data using datagridtextcolumn:

<wpftoolkit:datagridtextcolumn binding="{binding path=dob,stringformat='dd/mmm/yyyy'}" header="dob" width="120" /> 

however, if have column has editable data, i'll use datagridtemplatecolumn instead.

<wpftoolkit:datagridtemplatecolumn xheader="department name"  >     <wpftoolkit:datagridtemplatecolumn.celltemplate>         <datatemplate>             <combobox width="175"                itemssource="{binding source={staticresource alldepartmentsdatasource}}"                selectedvalue="{binding departmentid}" selectedvaluepath="departmentid" displaymemberpath="departmentname"                verticalalignment="center"                 >             </combobox>         </datatemplate>     </wpftoolkit::datagridtemplatecolumn.celltemplate> </twpftoolkit:datagridtemplatecolumn> 

the problem is, every 1 of datagridtextcolumns, need add isreadonly parameter, otherwise user can (incorrectly) edit data:

<wpftoolkit:datagridtextcolumn isreadonly="true" binding="{binding path=dob,stringformat='dd/mmm/yyyy'}" header="dob" width="120" /> 

is there way add "isreadonly" setting globally, in resourcedictionary file, of datagridtextcolumns...?

i can add global styles datagrid, datagridcolumnheader, datagridrow, , datagridcell, if try define style targettype of datagridtextcolumn, visual studio complains datagridtextcolumn not derived frameworkelement or frameworkcontentelement.

<style targettype="{x:type wpftoolkit:datagridtextcolumn}">     <setter property="isreadonly" value="true"/> </style> 

i can add isreadonly grid style, makes columns uneditable !

can think of quick , easy way add simple property datagridtextcolumns ?

update:

my solution has been (reluctantly) add loaded handler each of datagrids, runs code:

void grdgrid_loaded(object sender, routedeventargs e) {     datagrid dg = (datagrid)sender;     foreach (datagridcolumn col in dg.columns)     {         datagridtextcolumn textcol = col datagridtextcolumn;         if (textcol != null)         {             textcol.isreadonly = true;         }         else         {             //  datagridcolumn isn't of type "datagridtextcolumn", nothing.          }     } } 

you could, of course, put in own datagrid-inherited control, rather repeating each of datagrids.

(sigh.) why didn't ms make isreadonly attachable property..? would've made life easier!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -