Skip to content

[ContentSizer]: Fix the implicit setup issues for the DataTable used. - #20

Open
hoshiizumiya wants to merge 1 commit into
lgztx96:masterfrom
hoshiizumiya:fix/ContentSizer
Open

hoshiizumiya wants to merge 1 commit into
lgztx96:masterfrom
hoshiizumiya:fix/ContentSizer

Conversation

@hoshiizumiya

Copy link
Copy Markdown
Contributor

The current modifications to ContentSizer essentially add a mode where it serves only as a drag input surface without directly modifying the target control's dimensions, specifically designed to let DataColumn take over column width calculation.

Original Behavior

The original ContentSizer was designed to:

  1. If no TargetControl is set, automatically find the nearest parent FrameworkElement during Loaded.
  2. Read the target's ActualWidth/ActualHeight when dragging begins.
  3. Directly set during dragging:
targetControl.Width(...)

or:

targetControl.Height(...)

Therefore, it is a control that "directly modifies FrameworkElement dimensions."

This works well for ordinary panels, content areas, and similar scenarios, but is not suitable for DataTable column widths. DataTable column widths are actually determined by a combination of:

  • DataColumn.DesiredWidth
  • Auto / Pixel / Star
  • DataTable's parsed column width cache
  • Corresponding column arrangement in DataRow
  • ColumnSpacing
  • TreeViewItem indentation

If ContentSizer directly sets DataColumn.Width while DataTable re‑Measure/Arrange based on DesiredWidth, two competing layout states are introduced.

Change 1: Distinguish Between "Not Set" and "Explicitly Set to null"

Previously:

if (TargetControl() == nullptr)
{
    TargetControl(FindAscendant<FrameworkElement>(*this));
}

Now:

if (ReadLocalValue(TargetControlProperty) == DependencyProperty::UnsetValue())
{
    TargetControl(FindAscendant<FrameworkElement>(*this));
}

The distinction is important.

Previous Semantics

The following two cases could not be distinguished:

// Never set
TargetControl == nullptr
// User intentionally disables automatic targeting
TargetControl(nullptr)

Both would automatically find the parent control during Loaded.

Even if DataColumn called:

_columnSizer.TargetControl(nullptr);

ContentSizer::OnLoaded would still reassign it to the nearest parent, usually DataColumn itself.

As a result, during dragging, ContentSizer would still execute:

DataColumn.Width(newWidth);

Current Semantics

Using ReadLocalValue allows distinction:

  • UnsetValue: The property was never set; retains the original automatic parent lookup behavior.
  • Local value is nullptr: The caller explicitly requests no target; automatic lookup no longer occurs.

Therefore, in DataColumn:

_columnSizer.TargetControl(nullptr);

now truly takes effect.

Issues Resolved

It prevents ContentSizer from directly setting DataColumn.Width, primarily fixing:

  • Progressive drift between ContentSizer and the mouse.
  • The column appearing "stuck" after dragging to a certain position.
  • Text in the first column shifting rightward during dragging.
  • DataTable arranging based on DesiredWidth while ContentSizer simultaneously modifies FrameworkElement.Width, causing headers and rows to use different width sources.
  • Star columns redistributing remaining space while other columns move in the opposite direction.
  • Drag‑triggered layout feedback loops where, after the Sizer's own position changes, accumulated mouse displacement no longer corresponds to control position.

Change 2: Continue Manipulation Flow When Target Is Explicitly null

New logic added:

if (ReadLocalValue(TargetControlProperty) != DependencyProperty::UnsetValue())
{
    return true;
}

Corresponding changes exist for the vertical direction.

Why Returning true Is Necessary

SizerBase::OnManipulationDelta contains this control flow:

if (!overridable().OnDragHorizontal(horizontalChange))
{
    return;
}

base_type::OnManipulationDelta(e);

Previously, when TargetControl == nullptr, ContentSizer::OnDragHorizontal returned false, causing SizerBase to prematurely end Manipulation handling.

But DataColumn now needs to listen to ContentSizer's:

  • ManipulationStarted
  • ManipulationDelta
  • ManipulationCompleted

and then calculate column widths itself.

Therefore, the explicit‑null mode needs to convey:

I am not directly modifying any FrameworkElement.Width, but this drag is valid; please continue processing Manipulation events.

Hence, returning true.

This allows DataColumn to receive events here:

DataColumn.cpp

_columnSizer.ManipulationStarted(...);
_columnSizer.ManipulationDelta(...);
_columnSizer.ManipulationCompleted(...);

DataColumn then converts accumulated mouse displacement into a true Pixel DesiredWidth, and DataTable uniformly arranges headers and rows.

Current Three Behaviors

TargetControl State ContentSizer Behavior
Never set, i.e. UnsetValue Automatically finds nearest parent during Loaded; behavior unchanged from original
Explicitly set to a valid control Directly sets the target's Width/Height; behavior unchanged from original
Explicitly set to nullptr Does not modify any control dimensions; only preserves drag input and Manipulation events

DataTable uses the third mode.

What It Does Not Handle

The modifications to ContentSizer themselves do not handle:

  • Star column width calculation.
  • Synchronizing DataRow.
  • Restoring saved column widths.
  • Handling TreeView indentation.
  • Calculating ActualColumnWidth.
  • Calling GridLengthHelper::FromPixels.

These are all handled by DataColumn/DataTable.

ContentSizer handles only one thing:

It no longer bypasses DataTable's column layout system to directly modify DataColumn.Width, while continuing to provide mouse drag events.

Impact on the General ContentSizer API

This does change a previously ill‑defined API behavior:

Previously:

TargetControl(nullptr);

meant "please automatically find the parent element."

Now:

TargetControl(nullptr);

means "explicitly do NOT use a target control."

"Automatically find the parent element" now corresponds only to leaving TargetControl entirely unset.

General usage remains unchanged, but code that relied on "explicitly set null first and still auto‑find parent after Loaded" may be affected.

There is also one limitation: this explicit‑null mode currently primarily serves pointer‑based Manipulation. The keyboard adjustment in SizerBase directly calls OnDragHorizontal/Vertical, which does not generate the ManipulationDelta that DataColumn currently listens for, so DataColumn's keyboard‑based column width adjustments will not take effect through this path. For a complete control‑level solution, it would be best to later add a formal DragDelta event to SizerBase/ContentSizer, rather than using ManipulationDelta as a notification interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant