c# - WPF Datagrid row validation error not clearing after edit -


using datagrid in wpf, trying correct behaviour while using error validation via inotifydataerrorinfo.

i have observablecollection of class implements interface, bind collection datagrid. when there error, cell have red border, , row have red ! in front. default, good. when still editing, when error gone, red border , red ! both disappear. far, good!

however, when leave row (via keyboard enter/tab or mouse), come , remove error, red cell border disappears, red ! stays.

i aware question has been raised before, example here: wpf datagrid validation errors not clearing. however, solutions there not resolve this, apart hiding row validation error altogether. (which, in combination second answer here quite ok...)

or problem rather user able leave editing mode of cell though there validation error? preferably, restrict this, , force resolution of error first, before further editing can occur, don't know how enforce without lots of code...

here xml (the rowvalidationerrortemplate comes here: link):

<usercontrol x:class="customdg"              ...etc...              mc:ignorable="d"               d:designheight="300" d:designwidth="300"              d:datacontext="{d:designinstance type=viewmodels:testviewmodel}">     <grid>         <datagrid             itemssource="{binding path=testcollection}" autogeneratecolumns="false"             rowheight="18" canuserresizerows="false" rowheaderwidth="18" >             <datagrid.rowvalidationerrortemplate>               <controltemplate>                 <grid margin="0,-2,0,-2"                     tooltip="{binding relativesource={relativesource                     findancestor, ancestortype={x:type datagridrow}},                     path=(validation.errors)[0].errorcontent}">                     <ellipse strokethickness="0" fill="red"                          width="{templatebinding fontsize}"                          height="{templatebinding fontsize}" />                     <textblock text="!" fontsize="{templatebinding fontsize}"                          fontweight="bold" foreground="white"                          horizontalalignment="center"  />                     </grid>                 </controltemplate>             </datagrid.rowvalidationerrortemplate>-->              <datagrid.columns>                 <datagridtextcolumn header="name" binding="{binding path=name,                      validatesonnotifydataerrors=true, mode=twoway, updatesourcetrigger=propertychanged}" >                 </datagridtextcolumn>             </datagrid.columns>         </datagrid>     </grid> </usercontrol> 

you need raise notifypropertychanged empty string after row committed or canceled edit refresh databinding object , refresh interface use that:

raisenotifypropertychanged("");  

Comments