Repository navigation
Description
Related to #26
Discovered as part of work on DataTable experiment in labs in this branch/commit here: CommunityToolkit/Labs-Windows@47f46df#diff-b874aea5366fbeacbd08eec0606a72bf3b458be31ff250be121b9c9f5ec7b49d
Basically, when the target control was being set in this scenario, the layout hadn't occurred yet on the, so the DesiredSize.Width is still '0'; which means the Width of the component is set to 0 and is never updated or changed making it invisible.
Instead, if the DesiredSize is not set yet, then we shouldn't manipulate the Width of the control, as the patch above did.
We set the Width property is that's modified by the sizing behavior:
Windows/components/Sizers/src/ContentSizer/ContentSizer.Events.cs
Lines 36 to 50 in 744e6ab
| protected override bool OnDragHorizontal(double horizontalChange) | |
| { | |
| if (TargetControl == null) | |
| { | |
| return true; | |
| } | |
| horizontalChange = IsDragInverted ? -horizontalChange : horizontalChange; | |
| if (!IsValidWidth(TargetControl, _currentSize + horizontalChange, ActualWidth)) | |
| { | |
| return false; | |
| } | |
| TargetControl.Width = _currentSize + horizontalChange; |
However, when we start to drag we measure the ActualWidth (or Height) here:
Windows/components/Sizers/src/ContentSizer/ContentSizer.Events.cs
Lines 24 to 33 in 744e6ab
| protected override void OnDragStarting() | |
| { | |
| if (TargetControl != null) | |
| { | |
| _currentSize = | |
| Orientation == Orientation.Vertical ? | |
| TargetControl.ActualWidth : | |
| TargetControl.ActualHeight; | |
| } | |
| } |
So, in theory we may just be able to remove this initial code all together?
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
Activity
michael-hawker commentedon Jun 12, 2023
Was able to write a test which I think demonstrates this issue:
Ah, and I found the key comment too:
So that's why we need to set the Width somewhere... I think I'll do this check in the
OnDragStartingthough instead? As then layout should be complete as user manipulation is occuring.michael-hawker commentedon Jun 12, 2023
I wonder if the original code re-used the
Widthfield over theActualWidthcalculated from layout? As testing without setting it initially seems to be working fine... And the tests...passBasically, this should be better behavior, as now the
ContentSizerdoesn't change any initial behavior until it is manipulated by the user.Opening a PR... :)
Fixes #85 - ContentSizer manipulating component Width to Zero on load
Fixes #85 - ContentSizer manipulating component Width to Zero on load
Fixes #85 - ContentSizer manipulating component Width to Zero on load