Skip to content

ContentSizer sets Width to 0 if layout hasn't completed #85

Closed

Description

@michael-hawker

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:

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:

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?

Activity

  1. michael-hawker commented on Jun 12, 2023

    @michael-hawker
    MemberAuthor

    Was able to write a test which I think demonstrates this issue:

    image

    Ah, and I found the key comment too:

    // as if it's NaN we won't be able to manipulate it.

    So that's why we need to set the Width somewhere... I think I'll do this check in the OnDragStarting though instead? As then layout should be complete as user manipulation is occuring.

  2. michael-hawker commented on Jun 12, 2023

    @michael-hawker
    MemberAuthor

    I wonder if the original code re-used the Width field over the ActualWidth calculated from layout? As testing without setting it initially seems to be working fine... And the tests...pass

    image

    Basically, this should be better behavior, as now the ContentSizer doesn't change any initial behavior until it is manipulated by the user.

    Opening a PR... :)

  3. added 2 commits that reference this issue on Jun 12, 2023
    4fd1e7d
    6106ce6
  4. added a commit that references this issue on Jun 13, 2023
    7885900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions