Click here to Skip to main content
12,254,527 members (65,247 online)
Click here to Skip to main content

Stats

602.7K views
18.4K downloads
297 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.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace DockingLibrary
{
    public abstract class Pane : UserControl , IDropSurface, ILayoutSerializable
    {
        public double PaneWidth = 150;
        public double PaneHeight = 150;

        public readonly List<DockableContent> Contents = new List<DockableContent>();


        DockManager _dockManager;
        public virtual DockManager DockManager
        {
            get { return _dockManager; }
            //set { _dockManager = value; }
        }


        public Pane(DockManager dockManager):this(dockManager, null) { }

        public Pane(DockManager dockManager, DockableContent content)
        {
            _dockManager = dockManager;

            if (content != null)
                Add(content);
        }

        public virtual void Add(DockableContent content)
        {
            if (DockManager != null)
                DockManager.Add(content);
            content.SetContainerPane(this);
            Contents.Add(content);
        }

        public virtual void Remove(DockableContent content)
        {
            if (DockManager != null)
                DockManager.Remove(content);
            content.SetContainerPane(null);
            Contents.Remove(content);
        }

        public virtual void Show(DockableContent content)
        {
            System.Diagnostics.Debug.Assert(Contents.Contains(content));
        }

        public virtual void Hide(DockableContent content)
        { 
        
        }

        public virtual void Show()
        {
            DockManager.DragPaneServices.Register(this);
        }

        public virtual void Hide()
        {
            DockManager.DragPaneServices.Unregister(this);
        }

        public virtual void Close()
        {
            DockManager.DragPaneServices.Unregister(this);
        }

        public virtual void Close(DockableContent content)
        {

        }
        
        
        public virtual bool IsHidden
        {
            get { return false; }
        }

        public virtual void SaveSize()
        {

        }


        public virtual DockableContent ActiveContent
        {
            get { return null; }
            set { }
        }

        protected virtual void DragContent(DockableContent contentToDrag, Point startDragPoint, Point offset)
        {
            Remove(contentToDrag);
            DockablePane pane = new DockablePane(DockManager);
            //pane = new DockablePane();
            //pane.DockManager = DockManager;
            pane.Add(contentToDrag);
            pane.Show();
            DockManager.Add(pane);
            //DockManager.Add(contentToDrag);
            FloatingWindow wnd = new FloatingWindow(pane);
            pane.ChangeState(PaneState.DockableWindow);
            DockManager.Drag(wnd, startDragPoint, offset);
        }

        public virtual void RefreshTitle()
        { 
        
        }

        #region Membri di IDropSurface 

        public Rect SurfaceRectangle
        {
            get 
            {
                if (IsHidden)
                    return new Rect();
                
                return new Rect(PointToScreen(new Point(0,0)), new Size(ActualWidth, ActualHeight)); 
            }
        }

        public virtual void OnDragEnter(Point point)
        {
            DockManager.OverlayWindow.ShowOverlayPaneDockingOptions(this);
        }

        public virtual void OnDragOver(Point point)
        {
            
        }

        public virtual void OnDragLeave(Point point)
        {
            DockManager.OverlayWindow.HideOverlayPaneDockingOptions(this);
        }

        public virtual bool OnDrop(Point point)
        {
            return false;
        }

        #endregion

        #region ILayoutSerializable Membri di

        public virtual void Serialize(XmlDocument doc, XmlNode parentNode)
        {
            parentNode.Attributes.Append(doc.CreateAttribute("Width"));
            parentNode.Attributes["Width"].Value = PaneWidth.ToString();
            parentNode.Attributes.Append(doc.CreateAttribute("Height"));
            parentNode.Attributes["Height"].Value = PaneHeight.ToString();

            foreach (ManagedContent content in Contents)
            {
                DockableContent dockableContent = content as DockableContent;
                if (dockableContent != null)
                {
                    XmlNode nodeDockableContent = doc.CreateElement(dockableContent.GetType().ToString());
                    parentNode.AppendChild(nodeDockableContent);
                }
            }
        }

        public virtual void Deserialize(DockManager managerToAttach, XmlNode node, GetContentFromTypeString getObjectHandler)
        {
            _dockManager = managerToAttach;

            PaneWidth = double.Parse(node.Attributes["Width"].Value);
            PaneHeight = double.Parse(node.Attributes["Height"].Value);

            foreach (XmlNode nodeDockableContent in node.ChildNodes)
            {
                DockableContent content = getObjectHandler(nodeDockableContent.Name);
                Add(content);
                Show(content);
            }

            DockManager.DragPaneServices.Register(this);
        }

        #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...

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