c# - Need to control look of textbox in DataGridTemplateColumn -
i have wpf datagrid datagridtextcolumns next datagridtemplatecolumns. cells in template columns contain textbox disable when checkbox checked. problem look/behavior of cells in these 2 types of columns not match when being edited. in xaml below, have set background of textbox in template column match cell in, way textbox in text column works. need textbox in template column turn white while being edited, textbox in text column.
here xaml:
<datagridtextcolumn header="rh" minwidth="50" binding="{binding horizontalresistivity, stringformat=n2, mode=twoway}"/> <datagridtemplatecolumn header="rh min" minwidth="50" > <datagridtemplatecolumn.celltemplate> <datatemplate> <textbox x:name="rmin" text="{binding horizontalresistivitymin, stringformat=n2, mode=twoway}" horizontalalignment="stretch" verticalalignment="stretch" borderthickness="0" background="{binding background, relativesource={relativesource findancestor, ancestortype={x:type datagridcell}}}"/> <datatemplate.triggers> <datatrigger binding="{binding path=horizontalresistivityisfixed}" value="true"> <setter targetname="rmin" property="isenabled" value="false" /> </datatrigger> </datatemplate.triggers> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn>
i have come reasonable close answer need. abandoned datagridtemplatecolumn , reverted datagridtextcolumn using before determined data grid cell had disabled. here xaml:
<datagridtextcolumn header="rh min" minwidth="50" binding="{binding horizontalresistivitymin, stringformat=n2, mode=twoway}"> <datagridtextcolumn.cellstyle> <style targettype="datagridcell"> <style.triggers> <datatrigger binding="{binding horizontalresistivityisfixed}" value="true"> <setter property="isenabled" value="false"/> </datatrigger> </style.triggers> </style> </datagridtextcolumn.cellstyle> <datagridtextcolumn.elementstyle> <style targettype="textblock"> <setter property="horizontalalignment" value="center"/> </style> </datagridtextcolumn.elementstyle> <datagridtextcolumn.editingelementstyle> <style targettype="textbox"> <setter property="horizontalalignment" value="center"/> </style> </datagridtextcolumn.editingelementstyle> </datagridtextcolumn> some explanation in order. after got isenabled property correctly bound, found textblock in cell no longer centered (it aligned left), hence elementstyle section aligned textblock. during editing cell contents shift left. during editing cell contents textbox, have editingelementstyle section aligns textbox.
that leave 1 issue, while editing textbox in column, whole row expands in height, maybe 10%. not happen in datagridtextcolumn not have disabling feature. not happen if don't include editingelementstyle section. seems adding datagridtextcolumn.cellstyle section messed defaults, , getting them beck pain.
Comments
Post a Comment