c# - WPF dragging within application throwing HRESULT E_FAIL from COM component -


i have few usercontrols in application need support dragging , dropping from, extracted code abstract class extending usercontrol (code below). when use in 1 control part of datatemplate in listbox, works fine.

when use in control can drop target, following exception on dodragdrop line:

comexception error hresult e_fail has been returned call com component 

this seems possibly related winforms interop, i'm not using winforms or com components - application pure wpf.

if continue execution, drop happened successfully. if surround dodragdrop call try block empty catch block, seems work expected. don't want ship code sort of hack though.

public abstract class draggableusercontrol : usercontrol {     private point? lastmousedownpoint;      protected override void  onmouseleftbuttondown(mousebuttoneventargs e)     {         base.onmouseleftbuttondown(e);          lastmousedownpoint = e.getposition(this);     }      protected override void onmousemove(system.windows.input.mouseeventargs e)     {         base.onmousemove(e);          if (e.leftbutton == mousebuttonstate.pressed && lastmousedownpoint != null)         {             point mouseposition = e.getposition(this);              if (((point)lastmousedownpoint - mouseposition).length > 3)             {                 begindrag();             }         }     }      protected override void onmouseleave(mouseeventargs e)     {         base.onmouseleave(e);          if (e.leftbutton == mousebuttonstate.pressed && lastmousedownpoint != null)         {             begindrag();         }     }      protected override void onmouseup(mousebuttoneventargs e)     {         base.onmouseup(e);          if (e.changedbutton == mousebutton.left)         {             lastmousedownpoint = null;         }     }      private void begindrag()     {         dataobject dragdata = new dataobject(dragformat, dragdata);          //try         //{             dragdrop.dodragdrop(this, dragdata, dragdropeffects.move);         //} catch {}          lastmousedownpoint = null;     }      protected abstract string dragformat     { get; }      protected abstract object dragdata     { get; }      protected abstract dragdropeffects dragallowedeffects     { get; } } 

a simple example created class seems work fine. used string , dragformat of dataformats.stringformat. worked fine. hans right, there no way repro.

im assuming whatever data object , somehow mucks data reflection or transfers back.

my suggestion break data object , see if particular part has same issue.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -