I have a WPF Grid with four columns containing only one GridSplitter. Two of the columns (0 and 3) are scalable, but one scalable column is not directly adjacent to the GridSplitter (column 2).
Columns 0 and 3 must have the same initial size. So I can’t put column 0 and 1 in a nested grid.
How can I solve this?
<Grid Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Fill="Blue" Margin="8" />
<Rectangle Grid.Column="1" Fill="Yellow" Margin="8" Width="24" />
<GridSplitter Grid.Column="2" Width="8" VerticalAlignment="Stretch" />
<Rectangle Grid.Column="3" Fill="Red" Margin="8" />
</Grid>
Edit: I solved it with the help of nickolay.laptev
<Grid Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Fill="Blue" Margin="8" />
<Rectangle Grid.Column="1" Fill="Yellow" Margin="8 8 16 8" Width="24" />
<GridSplitter Grid.Column="1" Width="8" VerticalAlignment="Stretch" HorizontalAlignment="Right" ResizeBehavior="PreviousAndNext" />
<Rectangle Grid.Column="2" Fill="Red" Margin="8" />
</Grid>
I offer 2 options:
If preview is enabled use GridSplitter.DragCompleted event. Change required columns width in it.
If preview is disabled use another event with Preview prefix.
It fixed my problem.