Fix: DataGrid last column resize to view width#3417
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request addresses a WPF DataGrid layout quirk where star-sized (Width="*") columns initially render at their MinWidth when the grid starts empty, causing the last/main column to only fill remaining width after a window resize (Fixes #3416).
Changes:
- Adds a one-shot
LoadingRowhandler to force star column width recomputation after the first row is realized. - Updates the DNS lookup results grid so the
Resultcolumn usesWidth="*"and enables text wrapping. - Slightly increases the query type
ComboBoxwidth (80 → 100).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
Source/NETworkManager/Views/DNSLookupView.xaml |
Makes the results grid nameable and hooks LoadingRow; sets the last column to Width="*" with wrapping so it fills remaining width on first paint. |
Source/NETworkManager/Views/DNSLookupView.xaml.cs |
Implements a one-shot LoadingRow handler that re-triggers star column measurement via dispatcher after the first row loads. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Force star-sized DataGrid columns to recompute on first row load. Without this, an | ||
| // initially empty DataGrid sizes star columns to MinWidth because the inner ScrollViewer | ||
| // measures with infinite width; only a window resize triggers a correct re-measure. | ||
| private void DataGridResults_LoadingRow(object sender, DataGridRowEventArgs e) | ||
| { | ||
| DataGridResults.LoadingRow -= DataGridResults_LoadingRow; | ||
|
|
||
| Dispatcher.BeginInvoke(new Action(() => | ||
| { | ||
| foreach (var column in DataGridResults.Columns) | ||
| { | ||
| if (!column.Width.IsStar) | ||
| continue; | ||
|
|
||
| var width = column.Width; | ||
| column.Width = 0; | ||
| column.Width = width; | ||
| } | ||
| }), DispatcherPriority.ContextIdle); | ||
| } |
There was a problem hiding this comment.
Done in commit 353e69a. Extracted the duplicated one-shot handler into a DataGridHelper.RefreshStarColumnsOnFirstRow attached property in NETworkManager.Utilities.WPF/DataGridHelper.cs. All 14 XAML views now use wpfHelper:DataGridHelper.RefreshStarColumnsOnFirstRow="True" (using the existing namespace alias in each file) instead of event handler bindings, and the duplicated handler methods have been removed from all 14 code-behind files.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ched property Agent-Logs-Url: https://github.com/BornToBeRoot/NETworkManager/sessions/090031d0-133d-4e38-becd-526f4b8dd846 Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Changes proposed in this pull request
Related issue(s)