question

StefanSchmidt-6201 avatar image
0 Votes"
StefanSchmidt-6201 asked StefanSchmidt-6201 answered

First Window can not recieve MouseEvents after dragging a separate one with my mouse

Hello,

i have created a second Window class to hold from a Wrap Panel a bitmap of a control inside the WrapPanwel. The WrapPanel lays in the first Application Main Window. So while holding my mouse pressed and dragging the second and extra Window class over the first one,, i can get or receive no kind of Mouse Events like MouseEnter or Mouse leave , i have tried all that to apply, but has ever worked:

_PreviewPanelSortWindow.IsHitTestVisible = false;
_PreviewPanelSortWindow.Topmost = true;
_PreviewPanelSortWindow.IsEnabled = false;
_PreviewPanelSortWindow.Show();
_PreviewPanelSortWindow.Owner = Application.Current.MainWindow;
this.Focus();
Application.Current.MainWindow.Activate();

Did anyone has an idea, could i hook a control may with native code..,, how could i bypass this restriction?

Thanks...

windows-wpf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@StefanSchmidt-6201, based on your description, I am not full understand your meaning.
->So while holding my mouse pressed and dragging the second and extra Window class over the first one,, i can get or receive no kind of Mouse Events like MouseEnter or Mouse leave
Specially I could not understand the sentence. I recommend that you could provide a picture and completed code with me so that I can know your meaning clearly.

0 Votes 0 ·
StefanSchmidt-6201 avatar image
0 Votes"
StefanSchmidt-6201 answered

think have solved the problem, with implementing this lines of code.

public static class WindowHelper
{
[DllImport("user32.dll", SetLastError = true)]
static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

     [DllImport("user32.dll")]
     static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);

     const int WS_EX_TRANSPARENT = 0x00000020;
     const int GWL_EXSTYLE = (-20);

     public static void SetWindowExTransparent(IntPtr hwnd)
     {
         var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
         SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | 
        WS_EX_TRANSPARENT);
     }
 }


protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(this).Handle;
WindowHelper.SetWindowExTransparent(hwnd);
}

I can not us Dragmove and have to bring the Window after the cursor manually, but it works this way. The function is meant to create the window transparent for mouse clicks.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

StefanSchmidt-6201 avatar image
0 Votes"
StefanSchmidt-6201 answered StefanSchmidt-6201 edited

Hello,


hmmm,, thats yet strange to explain again,, also i have inside a wrapPanel positioned some kind of other panels, that i want after longer holding down the mousebutton getting out the WrapPanel to can move them around. For that reason i created a separate Window or Popup Control to first take out the nested Panel out of the WrapPanel and pout it into that Window or Popup to can then with Dragmove move it around to find somewhere a spot to can lay it down again. Similar like in Windows Explorer if ya wanna drag and move a folder into another one.
There happens something in the WPF application, if i use Dragmove under may cursor appears that Window. Although i have set it to transparent and all that matter if it is position directly under my cursor i can slide with dragmove and the dragged control over my MainWindow where the Wrappanel is positioned and i plan to relocate object again. But there is the problem with the underlaying control below my cursor i can not trigger any MouseEvents on the MainWindow, as so seems the cursor is hidden by the hosting dragged object, if i position it with dragmove besides the cursor all events starts to fire and all is fine,, but directly under the cursor nothen of such events will occur, although the dragged window is transparent , not hittest visible and all such properties, and has a transparent background brush

a code example makes no sense like written above,, simply has another object ,, used drag move on it, to use it above my MainWindow and try to get MouseEvents with that same cursor that has dragged below his shape the control

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.