Repository navigation
Closed
Description
Describe the bug
"CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109"
Consider a grid with 3 columns and 2 splitters as following:
<Grid
VerticalAlignment="Stretch"
BorderBrush="{ThemeResource SystemControlHighlightChromeHighBrush}"
BorderThickness="0,0,1,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300*" MinWidth="100" />
<ColumnDefinition Width="Auto" MinWidth="6" />
<ColumnDefinition Width="300" MinWidth="32" />
<ColumnDefinition Width="Auto" MinWidth="6" />
<ColumnDefinition Width="300" MinWidth="32" />
</Grid.ColumnDefinitions>
<Border
Grid.Row="0"
Grid.Column="0"
Background="MidnightBlue">
<TextBlock Text="This text is in a column with 1* Width - This is what causes the second splitter not to work." TextWrapping="Wrap" />
</Border>
<Border Grid.Row="0" Grid.Column="2">
<TextBlock Text="This column resizes properly, and if it's the only one after the 1* column, it also resizes properly." TextWrapping="Wrap" />
</Border>
<Border
Grid.Row="0"
Grid.Column="4"
Background="DarkRed">
<TextBlock Text="This text Is not resizing - Grid.Column.Width = 300 - ResizeBehavior=PreviousAndNext" TextWrapping="Wrap" />
</Border>
<!-- Column Grid Splitter -->
<controls:GridSplitter
Grid.Column="1"
Width="16"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Auto" />
<!-- Row Grid Splitter -->
<controls:GridSplitter
Grid.Column="3"
Width="16"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Auto" />
</Grid>Splitter at Column 1 works fine, but splitter at Column 3 does not resize Column 4 as expected.
Steps to reproduce
Run the attached sample.
Expected behavior
Given that the splitter is configured to resize PreviousAndNext, it is supposed to resize both columns.
Screenshots
GridSplitter.Bug.2024-02-19.222346.mp4
Code Platform
- UWP
- WinAppSDK / WinUI 3
- Web Assembly (WASM)
- Android
- iOS
- MacOS
- Linux / GTK
Windows Build Number
- Windows 10 1809 (Build 17763)
- Windows 10 1903 (Build 18362)
- Windows 10 1909 (Build 18363)
- Windows 10 2004 (Build 19041)
- Windows 10 20H2 (Build 19042)
- Windows 10 21H1 (Build 19043)
- Windows 10 21H2 (Build 19044)
- Windows 10 22H2 (Build 19045)
- Windows 11 21H2 (Build 22000)
- Other (specify)
Other Windows Build number
Any version of windows
App minimum and target SDK version
- Windows 10, version 1809 (Build 17763)
- Windows 10, version 1903 (Build 18362)
- Windows 10, version 1909 (Build 18363)
- Windows 10, version 2004 (Build 19041)
- Windows 10, version 2104 (Build 20348)
- Windows 11, version 22H2 (Build 22000)
- Other (specify)
Other SDK version
No response
Visual Studio Version
2022
Visual Studio Build Number
latest
Device form factor
Desktop
Additional context
<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.0.240109" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
</ItemGroup>
Help us help you
Yes, I'd like to be assigned to work on this item.
Metadata
Metadata
Assignees
Labels
No labels
Activity
michael-hawker commentedon Feb 23, 2024
Thanks for the detailed report @abdes and offering to dig in more, a good place to start debugging is probably in these methods here: https://github.com/CommunityToolkit/Windows/blob/main/components/Sizers/src/GridSplitter/GridSplitter.Events.cs
Could be something with getting the right column and bounds checks, or could be something with the logic of determining if the column is resizable? Would have suspected for us to see this before, but I think normally there's usually a single grid-splitter in a two-column setup, so probably why we haven't seen it before.
Thanks, I've assigned this to you for now, let us know if you need any help!
abdes commentedon Feb 23, 2024
The problem is indeed in the way the GridSplitter decides how to resize the current and sibling columns. When both are not
Staritems, and the vector contains anotherStaritem (i.e. my scenario), the GridSplitter only resizes the current item, which makes thedeltaget applied to theStaritem and not to the sibling.In a scenario with only 2 items and a splitter, this does not show, because the delta gets automatically applied by the grid layout to the sibling.
If you look at the code at
Windows/components/Sizers/src/GridSplitter/GridSplitter.Events.cs
Lines 53 to 74 in f9ce94a
We can see that the method bails out immediately after changing the first row with fixed size (same applies to
OnDragHorizontalfor columns). It should not do that. It should also check if the other row is also fixed size and apply the change to it in order to ensure that the delta does not get applied to anotherStaritem in the vector.@michael-hawker I submitted a PR with a fix, please check it.
fix: resize both current and sibling when they are both fixed size
fix: resize both current and sibling when they are both fixed size
fix: check constraints before allowing the resize to proceed
Jay-o-Way commentedon Mar 8, 2024
But, you expect two columns to resize, while they are both fixed sizes. That's a contradictory design.
abdes commentedon Mar 8, 2024
fix: resize both current and sibling when they are both fixed size
fix: check constraints before allowing the resize to proceed