Click here to Skip to main content
15,885,917 members
Articles / Desktop Programming / WPF

DockPanel Splitter Control for WPF

Rate me:
Please Sign up or sign in to vote.
4.50/5 (19 votes)
10 Aug 2009CPOL 213.6K   6.8K   55   43
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.

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

XML
<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)


Written By
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Code Behind Pin
Jason McPeak15-Dec-09 5:58
Jason McPeak15-Dec-09 5:58 
GeneralWell done! Pin
brents11-Dec-09 14:25
brents11-Dec-09 14:25 
GeneralTo add this code to your own assembly... Pin
SerialHobbyist17-Aug-09 3:02
SerialHobbyist17-Aug-09 3:02 
AnswerRe: To add this code to your own assembly... Pin
objo17-Aug-09 6:33
objo17-Aug-09 6:33 
GeneralRe: To add this code to your own assembly... Pin
Jason McPeak15-Dec-09 4:48
Jason McPeak15-Dec-09 4:48 
GeneralRe: To add this code to your own assembly... Pin
objo15-Dec-09 4:57
objo15-Dec-09 4:57 
GeneralOpen Source SplitContainer Pin
Weifen Luo10-Aug-09 16:00
Weifen Luo10-Aug-09 16:00 
GeneralRe: Open Source SplitContainer Pin
objo10-Aug-09 20:45
objo10-Aug-09 20:45 
thanks for the link! that's a good example of a user control! I like the adorner solution.
GeneralMy vote of 2 Pin
dartrax6-Aug-09 4:19
dartrax6-Aug-09 4:19 
AnswerRe: resizing out of client area Pin
objo9-Aug-09 9:57
objo9-Aug-09 9:57 
QuestionIs there a way to change the appearance of the DockPanel splitter? Pin
Chris Boarman20-Jul-09 16:22
Chris Boarman20-Jul-09 16:22 
AnswerRe: Is there a way to change the appearance of the DockPanel splitter? Pin
objo21-Jul-09 20:11
objo21-Jul-09 20:11 
GeneralIs ProprtionalResize setting can be set independently for each panel ??? like the dock position (Dock.right for ex.) Pin
Sazuke-kun30-May-09 15:42
Sazuke-kun30-May-09 15:42 
GeneralRe: Is ProprtionalResize setting can be set independently for each panel ??? like the dock position (Dock.right for ex.) Pin
Sazuke-kun30-May-09 15:46
Sazuke-kun30-May-09 15:46 
Generalhi very nice but :) Pin
Sazuke-kun24-May-09 16:53
Sazuke-kun24-May-09 16:53 
AnswerRe: hi very nice but :) Pin
objo24-May-09 21:08
objo24-May-09 21:08 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 6:28
Sazuke-kun25-May-09 6:28 
GeneralRe: hi very nice but :) Pin
objo25-May-09 12:34
objo25-May-09 12:34 
GeneralRe: hi very nice but :) [modified] Pin
Sazuke-kun25-May-09 12:39
Sazuke-kun25-May-09 12:39 
GeneralRe: hi very nice but :) Pin
objo25-May-09 12:38
objo25-May-09 12:38 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 12:39
Sazuke-kun25-May-09 12:39 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 12:44
Sazuke-kun25-May-09 12:44 

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

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