Implementing a multidock window system (like blend, visual studio) in WPF

社会主义新天地 提交于 2019-11-30 03:57:23

To support the scenarios you illustrate in your question a single DockPanel would suffice, so all you need to write is handlers for OnDragEnter, OnDragOver, OnDragLeave, and OnDragDrop. I generally use a single event handler because the handling of these four events is so similar:

OnDragEnter & OnDragOver:

  1. Compute which edge and which location in DockPanel the item will be dropped
  2. Remove any existing adorner
  3. Add rectangular adorner to show drop location

OnDragLeave:

  1. Remove any existing adorner

OnDragDrop:

  1. Remove any existing adorner
  2. Compute which edge and which location in DockPanel the item will be dropped
  3. Remove dragged item from current panel, set DockPanel.Dock on it, and add it to new panel

Naturally you also have to handle dragging on the title bar and call DoDragDrop on the source object.

The two complexities here are:

  • Deciding whether a DockPanel is sufficient for your needs or if you will need a more complex data structure
  • Making sure the geometric calculations take into account all possible configurations of windows

For a simple algorithm I would estimate it would take a week to get all the wrinkles ironed out. If you need a really complex data structure and the structure itself is unobvious, it could take serious time to figure that part out.

There's a great WPF Docking Library someone has published on codeproject.com, that has the functionality you're looking for. I used it myslef once, and i got it going pretty smoothly.

Check it out here : http://www.codeproject.com/KB/WPF/WPFdockinglib.aspx

AvalonDock is good.

http://avalondock.codeplex.com/

It's a pity you can't use it ;)

WPF already has controls which support docking (or that effect). Check Adam Nathan's WPF book WPF Unleashed, he covers it in part 2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!