Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

dockpanel

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.

like image 493
sjantke Avatar asked Jan 29 '26 23:01

sjantke


1 Answers

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>
like image 183
dkozl Avatar answered Jan 31 '26 13:01

dkozl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!