Example #1
0
        /// <summary>
        /// This event triggers when a tab is dragged outside the bonds of the tab control panel.
        /// We can use it to create a docking tab control.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChromeTabControl_TabDraggedOutsideBonds(object sender, TabDragEventArgs e)
        {
            TabBase draggedTab = e.Tab as TabBase;

            if (draggedTab is TabClass3)
            {
                return;                                                                        //As an example, we don't want out TabClass3 to form new windows, so we stop it here.
            }
            DockingWindow win = _openWindows.FirstOrDefault(x => x.DataContext == draggedTab); //check if it's already open

            if (win == null)                                                                   //If not, create a new one
            {
                win = new DockingWindow();

                win.Title            = draggedTab.TabName;
                win.DataContext      = draggedTab;
                win.Closed          += win_Closed;
                win.Loaded          += win_Loaded;
                win.LocationChanged += win_LocationChanged;
                win.Tag              = e.CursorPosition;
                win.Left             = e.CursorPosition.X - win.Width + 200;
                win.Top              = e.CursorPosition.Y - 20;
                win.Show();
            }
            else
            {
                Debug.WriteLine(DateTime.Now.ToShortTimeString() + " got window");
                MoveWindow(win, e.CursorPosition);
            }
            this._openWindows.Add(win);
            Debug.WriteLine(e.CursorPosition);
        }
        /// <summary>
        /// This event triggers when a tab is dragged outside the bonds of the tab control panel.
        /// We can use it to create a docking tab control.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChromeTabControl_TabDraggedOutsideBonds(object sender, TabDragEventArgs e)
        {
            TabBase draggedTab = e.Tab as TabBase;
            if (draggedTab is TabClass3)
                return;//We don't want out TabClass3 to form new windows, so we stop it here.
            DockingWindow win = _openWindows.FirstOrDefault(x => x.DataContext == draggedTab);//check if it's already open

            if (win == null)//If not, create a new one
            {
                win = new DockingWindow();
                win.Title = draggedTab.TabName;
                win.DataContext = draggedTab;
                win.Closed += win_Closed;
                win.Loaded += win_Loaded;
                win.LocationChanged += win_LocationChanged;
                win.Tag = e.CursorPosition;
                win.Show();
            }
            else
            {
                Debug.WriteLine(DateTime.Now.ToShortTimeString() + " got window");
                MoveWindow(win, e.CursorPosition);
            }
            this._openWindows.Add(win);
            Debug.WriteLine(e.CursorPosition);
        }
        protected bool TryDragTabToWindow(Point position, TabBase draggedTab)
        {
            if (draggedTab is TabClass3)
            {
                return(false);//As an example, we don't want TabClass3 to form new windows, so we stop it here.
            }
            if (draggedTab.IsPinned)
            {
                return(false);                                                                //We don't want pinned tabs to be draggable either.
            }
            DockingWindow win = OpenWindows.FirstOrDefault(x => x.DataContext == draggedTab); //check if it's already open

            if (win == null)                                                                  //If not, create a new one
            {
                win = new DockingWindow
                {
                    Title       = draggedTab?.TabName,
                    DataContext = draggedTab
                };

                win.Closed          += win_Closed;
                win.Loaded          += win_Loaded;
                win.LocationChanged += win_LocationChanged;
                win.Tag              = position;
                var scale = VisualTreeHelper.GetDpi(this);
                win.Left = position.X / scale.DpiScaleX - win.Width / 2;
                win.Top  = position.Y / scale.DpiScaleY - 10;

                win.Show();
            }
            else
            {
                Debug.WriteLine(DateTime.Now.ToShortTimeString() + " got window");
                MoveWindow(win, position);
            }
            OpenWindows.Add(win);
            return(true);
        }