c# - IsMouseOver and DragLeave not working properly -


i have grid/panel on ui can take drop action. control grid dynamically created content in (a viewbox containing stack panel of borders if matters).

when drag relevant information grid want change (regenerate) internal content , when drops or leaves should go normal. have 'change it' , 'put back' methods working fine, i'm having trouble determining when call them.

i have drag enter , drag leave events on grid. enter works great, leave not. mouse gets on top of content inside of grid fires drag leave event, changes content (and if puts out of child content fires drag enter again , flashes).

my first thought determine if mouse still on grid , ditch out without putting content back. doesn't seem working. here code drag leave:

        private void grid_dragleave(object sender, drageventargs e)     {         var wizard = datacontext wizardvm;         var gd = sender grid;          if (wizard == null || gd == null || gd.ismouseover ||             gd.children.cast<frameworkelement>().any(x => x.ismouseover)) return;          wizard.assembly.collapsepreview();     } 

as can see, tried iterate children of grid , see if mouse on true on of , ditch out, , still keeps returning false of , collapsing. thought ismouseover supposed tell me if mouse on @ if it's children of control...

ok after more research found seems working. ended having use visualtreehelper.hittest , use overload has callback , gets hit items if it's obscured. here final code:

    void grid_dragleave(object sender, drageventargs e)     {         var wizard = datacontext wizardvm;         var gd = sender grid;          if (wizard == null || gd == null) return;         point pt = e.getposition(this);         hitresults.clear();         visualtreehelper.hittest(gd, null, gridhittestresultcallback,             new pointhittestparameters(pt));          if (!hitresults.contains(gd))         {             wizard.assembly.isexpanded = false;         }     }      hittestresultbehavior gridhittestresultcallback(hittestresult result)     {         hitresults.add(result.visualhit);         return hittestresultbehavior.continue;     } 

basically gets point in relation full window, calls hittest point , overall grid i'm trying work with. callback populates list of visuals hit hit test. last original method checks if grid in list of hits , if not collapses it.

as side note changed .expandpreview() , .collapsepreview() methods .isexpanded property unrelated reasons... didn't want confused change...


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -