How to: Create a GridSplitter, that customizes the size of a DockPanel (C#, WPF)

gpuk360 picture gpuk360 · May 20, 2014 · Viewed 11.6k times · Source

How to: Create a GridSplitter, that customizes the size of a DockPanel (C#, WPF)

This is my GridSplitter code, but unfortunately it is not working: I am not allowed to change the size of my grid. I can see the GridSplitter, but I cannot use it.

<DockPanel DockPanel.Dock="Left" Name="dockPanel_1" Width="200">
    <StackPanel />
    <DockPanel />
</DockPanel>
<Grid>
    <GridSplitter ShowsPreview="True" Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" />
</Grid>
<DockPanel DockPanel.Dock="Right" Name="dockPanel_2">
    <StackPanel />
    <DockPanel />
</DockPanel>

PS: If you know how to save the changed size, so that its to the same size when restarting the application, just add to your post.

Thanks in advance.

Answer

dkozl picture dkozl · May 20, 2014

If you want to be able to resize columns/row then instead of DockPanel you can use Grid with GridSplitter

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <DockPanel Name="dockPanel_1">
        <StackPanel />
        <DockPanel />
    </DockPanel>
    <GridSplitter Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" ResizeBehavior="CurrentAndNext"/>
    <DockPanel Grid.Column="1" Name="dockPanel_2">
        <StackPanel />
        <DockPanel />
    </DockPanel>
</Grid>