Beispiel #1
0
 internal static extern IntPtr MonitorFromPoint(W32Point pt, uint dwFlags);
        //We use this to keep track of where the window is on the screen, so we can dock it later
        private void win_LocationChanged(object sender, EventArgs e)
        {
            Window win = (Window)sender;
            if (!win.IsLoaded)
                return;
            W32Point pt = new W32Point();
            if (!Win32.GetCursorPos(ref pt))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            Point absoluteScreenPos = new Point(pt.X, pt.Y);

            var windowUnder = FindWindowUnderThisAt(win, absoluteScreenPos);

            if (windowUnder != null && windowUnder.Equals(this))
            {
                Point relativePoint = this.PointFromScreen(absoluteScreenPos);//The screen position relative to the main window
                FrameworkElement element = this.MyChromeTabControl.InputHitTest(relativePoint) as FrameworkElement;//Hit test against the tab control

                if (element != null)
                {
                    ////test if the mouse is over the tab panel or a tab item.
                    if (CanInsertTabItem(element))
                    {
                        TabBase dockedWindowVM = (TabBase)win.DataContext;
                        ViewModelMainWindow mainWindowVm = (ViewModelMainWindow)this.DataContext;

                        mainWindowVm.ItemCollection.Add(dockedWindowVM);

                        win.Close();

                        mainWindowVm.SelectedTab = dockedWindowVM;

                        //We run this method on the tab control for it to grab the tab and position it at the mouse, ready to move again.
                        this.MyChromeTabControl.GrabTab(dockedWindowVM);

                    }
                }
            }
        }
Beispiel #3
0
 internal static extern bool GetCursorPos(ref W32Point pt);