wpf - Expander getting stuck after IsExpanded set to true by storyboard -


so have expander want have normal functionality (open , close own button) want different button expand when pressed (this button in header of expander). i'm using storyboard in event trigger button.click works, after expanded way normal button doesn't work, stays expanded. xaml below, prefer keep in xaml, come way in codebehind/viewmodel myself.

<expander x:name="indexexpander" isexpanded="true" grid.row="4" grid.columnspan="5" margin="10" maxheight="150">                 <expander.triggers>                     <eventtrigger sourcename="btnaddindex" routedevent="button.click">                         <beginstoryboard>                             <storyboard>                                 <booleananimationusingkeyframes storyboard.targetname="indexexpander" storyboard.targetproperty="isexpanded" begintime="0:0:0.25" duration="0:0:0.20" >                                     <discretebooleankeyframe keytime="0" value="true" />                                 </booleananimationusingkeyframes>                             </storyboard>                         </beginstoryboard>                     </eventtrigger>                 </expander.triggers>                 <expander.header>                     <stackpanel dockpanel.dock="left" orientation="horizontal">                         <textblock text="indexes" fontweight="bold"/>                          <!-- add/delete buttons-->                         <grid margin="10,0,0,0">                             <grid.columndefinitions>                                 <columndefinition width="50*"/>                                 <columndefinition width="50*"/>                             </grid.columndefinitions>                             <button grid.column="0" x:name="btnaddindex" command="{binding addindexcommand}" template="{staticresource addbuttontemplate}" isenabled="{binding iseditable}" margin="0,0,5,0" />                         </grid>                     </stackpanel>                 </expander.header> 

alright, following in footsteps here's did. got idea here, , adapted until worked correctly.

<expander.triggers>     <eventtrigger sourcename="btnaddcol" routedevent="button.click">         <beginstoryboard x:name="columnexpanderstory">             <storyboard>                 <booleananimationusingkeyframes storyboard.targetname="columnexpander" storyboard.targetproperty="isexpanded">                     <discretebooleankeyframe keytime="0" value="true" />                 </booleananimationusingkeyframes>              </storyboard>          </beginstoryboard>      </eventtrigger>      <eventtrigger routedevent="togglebutton.previewmouseup">          <removestoryboard beginstoryboardname="columnexpanderstory" />      </eventtrigger>   </expander.triggers> <expander.header> 

the problem storyboard overrides other bindings isexpanded property, has removed restore them (read more here). suggestion use togglebutton.checked event remove storyboard, didn't work me, "preview" events seemed have right timing. started previewmousedown, remove storyboard, on mouse toggle expander, meaning first click flip states , forth quickly. using previewmouseup got around issue.


Comments