Click here to Skip to main content
12,244,489 members (41,078 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

125.8K views
5K downloads
52 bookmarked
Posted

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

You may also be interested in...

Comments and Discussions

 
GeneralVery helpfull control - thank you! Pin
Member 99136139-May-14 9:42
memberMember 99136139-May-14 9:42 
QuestionNameSpace Error Pin
Surjeet Karmakar6-Nov-13 20:24
memberSurjeet Karmakar6-Nov-13 20:24 
SuggestionSuggestion For Expanders Pin
c_manboy6-Oct-13 14:53
memberc_manboy6-Oct-13 14:53 
QuestionExcellent control Pin
rquintalr27-May-13 4:15
memberrquintalr27-May-13 4:15 
GeneralMy vote of 5 Pin
Preev21-Mar-12 14:17
memberPreev21-Mar-12 14:17 
GeneralMy vote of 5 Pin
napnit10-Nov-11 2:11
membernapnit10-Nov-11 2:11 
QuestionHow to collapse one side, the other side, or both sides of the DockPanelSplitter control? Pin
CDCii27-Sep-11 9:55
memberCDCii27-Sep-11 9:55 
AnswerRe: How to collapse one side, the other side, or both sides of the DockPanelSplitter control? Pin
objo29-Sep-11 21:32
memberobjo29-Sep-11 21:32 
GeneralMy vote of 5 Pin
ferahl28-Apr-11 7:45
memberferahl28-Apr-11 7:45 
Generalsilverlight Pin
fel0nious1-Nov-10 11:50
memberfel0nious1-Nov-10 11:50 
GeneralRe: silverlight Pin
daniel Moody17-Jul-12 10:58
memberdaniel Moody17-Jul-12 10:58 
GeneralSplitter movement restriction Pin
Prasoon Chaudhary29-Apr-10 10:06
memberPrasoon Chaudhary29-Apr-10 10:06 
GeneralSystem.ArgumentException was unhandled Pin
kiol28-Jan-10 23:40
memberkiol28-Jan-10 23:40 
GeneralRe: System.ArgumentException was unhandled Pin
objo2-Feb-10 5:29
memberobjo2-Feb-10 5:29 
GeneralRe: System.ArgumentException was unhandled Pin
HHick1234512-May-10 2:42
memberHHick1234512-May-10 2:42 
GeneralCode Behind Pin
Jason McPeak15-Dec-09 4:41
memberJason McPeak15-Dec-09 4:41 
GeneralRe: Code Behind Pin
Jason McPeak15-Dec-09 5:39
memberJason McPeak15-Dec-09 5:39 
AnswerRe: Code Behind Pin
objo15-Dec-09 5:53
memberobjo15-Dec-09 5:53 
NewsRe: Code Behind Pin
Jason McPeak15-Dec-09 6:05
memberJason McPeak15-Dec-09 6:05 
GeneralRe: Code Behind Pin
Jason McPeak15-Dec-09 6:44
memberJason McPeak15-Dec-09 6:44 
GeneralRe: Code Behind Pin
Jason McPeak15-Dec-09 6:58
memberJason McPeak15-Dec-09 6:58 
GeneralWell done! Pin
brents11-Dec-09 15:25
memberbrents11-Dec-09 15:25 
GeneralTo add this code to your own assembly... Pin
SerialHobbyist17-Aug-09 4:02
memberSerialHobbyist17-Aug-09 4:02 
AnswerRe: To add this code to your own assembly... Pin
objo17-Aug-09 7:33
memberobjo17-Aug-09 7:33 
GeneralRe: To add this code to your own assembly... Pin
Jason McPeak15-Dec-09 5:48
memberJason McPeak15-Dec-09 5:48 
GeneralRe: To add this code to your own assembly... Pin
objo15-Dec-09 5:57
memberobjo15-Dec-09 5:57 
GeneralOpen Source SplitContainer Pin
Weifen Luo10-Aug-09 17:00
memberWeifen Luo10-Aug-09 17:00 
GeneralRe: Open Source SplitContainer Pin
objo10-Aug-09 21:45
memberobjo10-Aug-09 21:45 
GeneralMy vote of 2 Pin
dartrax6-Aug-09 5:19
memberdartrax6-Aug-09 5:19 
AnswerRe: resizing out of client area Pin
objo9-Aug-09 10:57
memberobjo9-Aug-09 10:57 
QuestionIs there a way to change the appearance of the DockPanel splitter? Pin
Chris Boarman20-Jul-09 17:22
memberChris Boarman20-Jul-09 17:22 
AnswerRe: Is there a way to change the appearance of the DockPanel splitter? Pin
objo21-Jul-09 21:11
memberobjo21-Jul-09 21:11 
GeneralIs ProprtionalResize setting can be set independently for each panel ??? like the dock position (Dock.right for ex.) Pin
Sazuke-kun30-May-09 16:42
memberSazuke-kun30-May-09 16: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 16:46
memberSazuke-kun30-May-09 16:46 
Generalhi very nice but :) Pin
Sazuke-kun24-May-09 17:53
memberSazuke-kun24-May-09 17:53 
AnswerRe: hi very nice but :) Pin
objo24-May-09 22:08
memberobjo24-May-09 22:08 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 7:28
memberSazuke-kun25-May-09 7:28 
GeneralRe: hi very nice but :) Pin
objo25-May-09 13:34
memberobjo25-May-09 13:34 
GeneralRe: hi very nice but :) [modified] Pin
Sazuke-kun25-May-09 13:39
memberSazuke-kun25-May-09 13:39 
GeneralRe: hi very nice but :) Pin
objo25-May-09 13:38
memberobjo25-May-09 13:38 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 13:39
memberSazuke-kun25-May-09 13:39 
GeneralRe: hi very nice but :) Pin
Sazuke-kun25-May-09 13:44
memberSazuke-kun25-May-09 13: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.

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