Skip to content

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

@michael-hawker

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions