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

Stefan Schmidt 96 Reputation points
2021-10-08T01:59:13.557+00:00

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 Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
{count} votes

Accepted answer
  1. Stefan Schmidt 96 Reputation points
    2021-10-08T22:10:47.063+00:00

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Stefan Schmidt 96 Reputation points
    2021-10-08T20:03:15.443+00:00

    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

    0 comments No comments