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

前端 未结 4 608
礼貌的吻别
礼貌的吻别 2020-12-28 21:52

How would you go about to implement a docking toolbox windowing system as seen in Expression Blend where you can dock toolbox windows in a lot of ways beneat each other, ove

4条回答
  •  囚心锁ツ
    2020-12-28 22: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.

提交回复
热议问题