Click here to Skip to main content
Licence CPOL
First Posted 21 Mar 2009
Views 68,026
Downloads 1,737
Bookmarked 44 times

DockPanel Splitter Control for WPF

By | 10 Aug 2009 | Article
A splitter control for the WPF DockPanel
Sample Image

Introduction

This control adds size adjustment functionality to elements of a DockPanel in the same way a GridSplitter can adjust the size of columns and rows in a Grid. When resizing the parent container, the elements will be resized proportionally unless the ProportionalResize property is set to False.

Using the Code

Add the OpenSourceControls namespace and add a DockPanelSplitter control after each panel you want to adjust. The DockPanel.Dock attribute controls which edge of the panel the splitter works on.

<Window x:Class="DockPanelSplitterDemo.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:osc="clr-namespace:OpenSourceControls"
    Title="DockPanelSplitter demo" Height="400" Width="600">
    <DockPanel>
        <Grid Name="LeftPane" DockPanel.Dock="Left" 
                      Width="200" MinWidth="40">
            <Rectangle Fill="LightBlue"/>
        </Grid>
        <osc:DockPanelSplitter DockPanel.Dock="Left" Width="4"/>
 
        <Grid Name="RightPane" DockPanel.Dock="Right" Width="80">
            <Rectangle Fill="Yellow"/>
        </Grid>
        <osc:DockPanelSplitter DockPanel.Dock="Right" Width="4"/>
        
        <Grid Name="TopPane" DockPanel.Dock="Top" 
                     Height="80" MinHeight="20">
            <Rectangle Fill="LightGreen"/>
        </Grid>
        <osc:DockPanelSplitter DockPanel.Dock="Top" Height="4"/>
        
        <Grid Name="BottomPane" DockPanel.Dock="Bottom" Height="70">
            <Rectangle Fill="LightPink"/>
        </Grid>
        <osc:DockPanelSplitter DockPanel.Dock="Bottom" Height="4"/>
        
        <Grid Name="MainPane" Background="Coral" >
            <Rectangle Fill="Coral"/>
        </Grid>
    </DockPanel>
</Window>

The proportional sizing mode can be turned off by setting the ProprtionalResize dependency property to False.

<osc:DockPanelSplitter DockPanel.Dock="Right" Width="4" ProportionalResize="False"/>

Links to Related Projects

  • WpfContrib DockSplitter (cannot find the control in ProportionalResize dependency property to False. Creating resizable panels with splitter bars (links don't work??)
  • Thumb example

Future Enhancements

  • Use the Thumb control instead of capturing mouse events

History

  • March 21, 2009 - First post
  • May 25, 2009 - Added proportional resizing
  • August 09, 2009 - Changed to custom control, added template demo, constrained size on client area

License

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

About the Author

objo



Norway Norway

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberPreev13:17 21 Mar '12  
GeneralMy vote of 5 Pinmembernapnit1:11 10 Nov '11  
QuestionHow to collapse one side, the other side, or both sides of the DockPanelSplitter control? PinmemberCDCii8:55 27 Sep '11  
AnswerRe: How to collapse one side, the other side, or both sides of the DockPanelSplitter control? Pinmemberobjo20:32 29 Sep '11  
GeneralMy vote of 5 Pinmemberferahl6:45 28 Apr '11  
Generalsilverlight Pinmemberfel0nious10:50 1 Nov '10  
GeneralSplitter movement restriction PinmemberPrasoon Chaudhary9:06 29 Apr '10  
GeneralSystem.ArgumentException was unhandled Pinmemberkiol22:40 28 Jan '10  
GeneralRe: System.ArgumentException was unhandled Pinmemberobjo4:29 2 Feb '10  
GeneralRe: System.ArgumentException was unhandled PinmemberHHick123451:42 12 May '10  
GeneralCode Behind PinmemberJason McPeak3:41 15 Dec '09  
GeneralRe: Code Behind PinmemberJason McPeak4:39 15 Dec '09  
AnswerRe: Code Behind Pinmemberobjo4:53 15 Dec '09  
NewsRe: Code Behind PinmemberJason McPeak5:05 15 Dec '09  
GeneralRe: Code Behind PinmemberJason McPeak5:44 15 Dec '09  
GeneralRe: Code Behind PinmemberJason McPeak5:58 15 Dec '09  
GeneralWell done! Pinmemberbrents114:25 1 Dec '09  
GeneralTo add this code to your own assembly... PinmemberSerialHobbyist3:02 17 Aug '09  
AnswerRe: To add this code to your own assembly... Pinmemberobjo6:33 17 Aug '09  
GeneralRe: To add this code to your own assembly... PinmemberJason McPeak4:48 15 Dec '09  
GeneralRe: To add this code to your own assembly... Pinmemberobjo4:57 15 Dec '09  
GeneralOpen Source SplitContainer PinmemberWeifen Luo16:00 10 Aug '09  
GeneralRe: Open Source SplitContainer Pinmemberobjo20:45 10 Aug '09  
GeneralMy vote of 2 Pinmemberdartrax4:19 6 Aug '09  
AnswerRe: resizing out of client area Pinmemberobjo9:57 9 Aug '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 10 Aug 2009
Article Copyright 2009 by objo
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid