Click here to Skip to main content
12,633,998 members (21,111 online)
Click here to Skip to main content

Stats

667K views
19.3K downloads
299 bookmarked
Posted

WPF Docking Library

, 17 Jul 2007 CPOL
A WPF library to easily integrate Windows docking features in applications like VS
DockingLibrary
DockingLibrary
bin
Debug
Release
ClassDiagram1.cd
icons
DockBottom.PNG
DockLeft.PNG
DockPane.PNG
DockRight.PNG
DockTop.PNG
Ritaglio.shs
Thumbs.db
images
DockBottom.PNG
DockLeft.PNG
DockPane.PNG
DockRight.PNG
DockTop.PNG
obj
Debug
Refactor
TempPE
themes
Release
Refactor
TempPE
themes
Properties
themes
DockingLibraryDemo
bin
Debug
Release
Icons
props.ico
view_remove.ico
view_tree.ico
obj
Debug
TempPE
Release
TempPE
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace DockingLibrary
{
    class DockablePane : Pane
    {
        public Dock Dock;
        
        public DockablePane(ManagedContent content, Dock dock)
        {
            Dock = dock;
            _tabs.TabStripPlacement = Dock.Bottom;
            

            Add(content);
        }
        private bool _hidden = false;

        public override bool Hidden
        {
            get
            {
                return _hidden;
            }
        }

        public override void Add(ManagedContent content)
        {
            base.Add(content);

            if (Contents.Count == 1)
            { 
                tbTitle.Text = content.Title;
                windowContent.Content = content.WindowContent;
            }
            else if (Contents.Count == 2)
            {
                ShowTabs();
                AddItem(Contents[0]);
                AddItem(content);
            }
            else
                AddItem(content);
        }

        public override void Remove(ManagedContent content)
        {
            base.Remove(content);

            RemoveItem(content);

            if (Contents.Count == 1)
            {
                RemoveItem(Contents[0]); 
                HideTabs();
                windowContent.Content = Contents[0].WindowContent;
                tbTitle.Text = Contents[0].Title;
            }
            else if (Contents.Count==0)
                windowContent.Content = null;
        }


        public override void Show()
        {
            if (!Hidden)
                return;

            if (Contents.Count == 1)
                windowContent.Content = Contents[0].WindowContent;
            else
            {
                foreach (ManagedContent content in Contents)
                    AddItem(content);

                windowContent.Content = _tabs;
            }

            _hidden = false;

            base.Show();
        }


        public override void Hide()
        {
            if (Hidden)
                return;

            //if (_tabs != null)
            //{
            foreach (TabItem item in _tabs.Items)
            {
                
                item.Content = null;
            }

            _tabs.Items.Clear();

            //}
            //else
            windowContent.Content = null;

            _hidden = true;

            base.Hide();
        }

        public override void AdjustSize()
        {
            if (Parent == null)
                return;

            Grid gridParent = (this.Parent as Grid).Parent as Grid;

            foreach (ColumnDefinition colDef in gridParent.ColumnDefinitions)
                if (!colDef.Width.IsStar)
                {
                    GridWidth = colDef.Width;
                    break;
                }
            foreach (RowDefinition rowDef in gridParent.RowDefinitions)
                if (!rowDef.Height.IsStar)
                {
                    GridHeight = rowDef.Height;
                    break;
                }

            base.AdjustSize();
        }


        #region Drag&Drop

        protected override void OnDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                panelDrag.Visibility = Visibility.Visible;
                e.Handled = true;
            }
            else
                e.Effects = DragDropEffects.None;
        }

        protected override void OnDragLeave(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
            else
                e.Effects = DragDropEffects.None;
        }

        protected override void OnDrop(object sender, DragEventArgs e)
        {
            panelDrag.Visibility = Visibility.Collapsed;
            e.Effects = DragDropEffects.None;
        }

        protected override void OnDragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                panelDrag.Visibility = Visibility.Visible;
                e.Handled = true;
            }
        }



        protected override void OnDropInto(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                FireOnDragEndEvent(e);

                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
        }

        protected override void OnDropDockLeft(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                FireOnDragEndEvent(e, Dock.Left);

                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
        }
        protected override void OnDropDockRight(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                FireOnDragEndEvent(e, Dock.Right);

                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
        }

        protected override void OnDropDockBottom(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                FireOnDragEndEvent(e, Dock.Bottom);

                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
        }

        protected override void OnDropDockTop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DockablePane)) ||
                e.Data.GetDataPresent(typeof(ManagedContent)))
            {
                FireOnDragEndEvent(e, Dock.Top);

                panelDrag.Visibility = Visibility.Collapsed;
                e.Handled = true;
            }
        } 
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

adospace.NET
Systems Engineer
Italy Italy
I bought my first computer in Nov 1991, 21st and I started programming with QBasic under MSDOS.
Today my main interest is developping applications with .NET and HTML5 stack.

You may also be interested in...

Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 17 Jul 2007
Article Copyright 2007 by adospace.NET
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid