-
May 3rd, 2025, 04:21 PM
#1
Thread Starter
Hyperactive Member
GridSplitters not worknig as expected.
Hi,
I have 4 columns in a grid with a GridSplitter between each (so technically 7 total).
My "Column 2" and Grid Column index 2 is the one I want to shrink/grow based on any of the GridSplitters being moved. So I have it's width set to "*".
My first splitter works fine, but splitters 2 and 3 don't work right at all. I've played around with Column 3 and Column 4 having a width of "0.5*", it works a bit better but still not right.
Behaviour I'm after.
Grid Splitter |
Drag Direction |
Desired Result |
Note |
1 |
Left |
Col 1 Shrink, Col 2 Grow |
|
1 |
Right |
Col 1 Grow, Col 2 Shrink |
|
2 |
Left |
Col 2 Shrink, Col 3 Grow |
|
2 |
Right |
Col 2 Grow, Col 3 Shrink |
|
3 |
Left |
Col 2 Shrink, Col 4 grow |
This might need some code behind, but I'd at least like Col 3 Shrink, Col 4 Grow. |
3 |
Right |
Col 2 Grow, Col 4 Shrink |
This might need some code behind, but I'd at least like Col 3 Grow, Col 4 Shrink. |
My example code is as follows:
Code:
<Window x:Class="WpfQueries.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfQueries"
mc:Ignorable="d"
Title="MainWindow" Height="840" Width="1280">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<!-- First Column -->
<TextBlock Text="Column 1" Grid.Column="0"/>
<!-- Splitter 1 -->
<GridSplitter Grid.Column="1" Width="5" Background="Black"/>
<!-- Second Column -->
<TextBlock Text="Column 2" Grid.Column="2"/>
<!-- Splitter 2 -->
<GridSplitter Grid.Column="3" Width="5" Background="Black"/>
<!-- Third Column -->
<TextBlock Text="Column 3" Grid.Column="4"/>
<!-- Splitter 3 -->
<GridSplitter Grid.Column="5" Width="5" Background="Black"/>
<!-- Fourth Column -->
<TextBlock Text="Column 4" Grid.Column="6"/>
</Grid>
</Window>
Eventually once I get this working, I plan on making Column 1, 3 & 4 expanders.
Do I need to create Multiple 3 columns grids with the 2nd column being a splitter and put them inside one another, like we would with Split containers in WinForms?
Any help would be appreciated.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|