Click here to Skip to main content
Click here to Skip to main content

Tagged as

DockPanel Splitter Control for WPF

, 10 Aug 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

objo

Norway Norway
No Biography provided

Comments and Discussions

 
AnswerRe: resizing out of client area Pinmemberobjo9-Aug-09 10:57 
QuestionIs there a way to change the appearance of the DockPanel splitter? PinmemberChris Boarman20-Jul-09 17:22 
AnswerRe: Is there a way to change the appearance of the DockPanel splitter? Pinmemberobjo21-Jul-09 21:11 
GeneralIs ProprtionalResize setting can be set independently for each panel ??? like the dock position (Dock.right for ex.) PinmemberSazuke-kun30-May-09 16:42 
GeneralRe: Is ProprtionalResize setting can be set independently for each panel ??? like the dock position (Dock.right for ex.) PinmemberSazuke-kun30-May-09 16:46 
Generalhi very nice but :) PinmemberSazuke-kun24-May-09 17:53 
AnswerRe: hi very nice but :) Pinmemberobjo24-May-09 22:08 
GeneralRe: hi very nice but :) PinmemberSazuke-kun25-May-09 7:28 
cool thx, i really like the fact that now because of your very nice splitter I can almost always use the dockpanel instead of the grid Smile | :)
 
The XAML is so much cleaner with only DockPanels and in the future i can always change it for a grid if my needs change.
 
Do you know if Dockpanels add processing overhead versus grid??
GeneralRe: hi very nice but :) Pinmemberobjo25-May-09 13:34 
GeneralRe: hi very nice but :) [modified] PinmemberSazuke-kun25-May-09 13:39 
GeneralRe: hi very nice but :) Pinmemberobjo25-May-09 13:38 
GeneralRe: hi very nice but :) PinmemberSazuke-kun25-May-09 13:39 
GeneralRe: hi very nice but :) PinmemberSazuke-kun25-May-09 13:44 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 10 Aug 2009
Article Copyright 2009 by objo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid