From 8de8ef265c4d18d31adb6862897965d3df409949 Mon Sep 17 00:00:00 2001 From: michael-hawker <24302614+michael-hawker@users.noreply.github.com> Date: Tue, 13 Jun 2023 17:32:51 -0700 Subject: [PATCH] Initial test to resize item columns based on header column --- .../DataTable/src/DataTable/DataColumn.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/DataTable/src/DataTable/DataColumn.cs b/components/DataTable/src/DataTable/DataColumn.cs index 3cacc38aa..1f9cbe805 100644 --- a/components/DataTable/src/DataTable/DataColumn.cs +++ b/components/DataTable/src/DataTable/DataColumn.cs @@ -48,13 +48,37 @@ public DataColumn() protected override void OnApplyTemplate() { + if (PART_ColumnSizer != null) + { + PART_ColumnSizer.TargetControl = null; + PART_ColumnSizer.ManipulationCompleted -= this.PART_ColumnSizer_ManipulationCompleted; + } + PART_ColumnSizer = GetTemplateChild(nameof(PART_ColumnSizer)) as ContentSizer; if (PART_ColumnSizer != null) { PART_ColumnSizer.TargetControl = this; + PART_ColumnSizer.ManipulationCompleted += this.PART_ColumnSizer_ManipulationCompleted; } base.OnApplyTemplate(); } + + private void PART_ColumnSizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) + { + var parent = this.FindAscendant(); + + // TODO: Would be nice for Visual Tree helpers to have limit on depth search, + // as could grab the direct Panel descendant and then search that for DataRow + // vs. exploring the whole Header content as well (which has a Panel in our case as well...) + + if (parent != null) + { + foreach (DataRow row in parent.FindDescendants().Where(element => element is DataRow)) + { + row.InvalidateArrange(); + } + } + } }