.net - Sorting DataGrid while animating cells causes exception -
i have created datagridcell template have applied 1 of columns so:
<datagridtextcolumn binding="{binding lastupdated}" isreadonly="true" canuserreorder="false" canusersort="false" canuserresize="false" cellstyle="{staticresource datagridcellstyle1}" />
and template looks this:
<controltemplate targettype="{x:type datagridcell}"> <controltemplate.resources> <storyboard x:key="cellchangedstoryboard"> <coloranimationusingkeyframes storyboard.targetproperty="(panel.background).(solidcolorbrush.color)" storyboard.targetname="dgc_border"> <easingcolorkeyframe keytime="0" value="lightgreen"/> <easingcolorkeyframe keytime="0:0:8" value="red"/> </coloranimationusingkeyframes> </storyboard> </controltemplate.resources> <border x:name="dgc_border" background="red"> <contentpresenter /> <i:interaction.triggers> <ei:timertrigger millisecondspertick="1000" > <ei:controlstoryboardaction storyboard="{staticresource cellchangedstoryboard}"/> </ei:timertrigger> </i:interaction.triggers> </border> </controltemplate>
in example triggering anim using blend timertrigger, doesnt matter how trigger animation, crashes try sort datagrid (by clicking on 1 of column headers)
if remove storyboard not crash on sort.
the exception invalidoperationexception: 'dgc_border' name cannot found in name scope of 'system.windows.controls.border'.
i suspect when datagrid sorts destroys or otherwise messes cells/columns , animation running can no longer find cell animating.
why exception happening , how stop it? thanks
update: seems work ok if use <controltemplate.triggers>
trigger storyboard. unfortunately no solution need play storyboard when bound property changes.
best come ditch blend triggers , use this:
<border x:name="dgc_border" background="red"> <contentpresenter snapstodevicepixels="{templatebinding snapstodevicepixels}" content="{binding lastupdated, notifyontargetupdated=true}"> <contentpresenter.triggers> <eventtrigger routedevent="binding.targetupdated"> <beginstoryboard storyboard="{staticresource rowchangedstoryboard}" /> </eventtrigger> </contentpresenter.triggers> </contentpresenter> </border>
i notice after grid sorts animations removed, not correct behavior me - want animations continue left off have save day.
Comments
Post a Comment