-
Notifications
You must be signed in to change notification settings - Fork 86
Improve DataTable control #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
9rnsr
wants to merge
10
commits into
CommunityToolkit:main
Choose a base branch
from
9rnsr:ImproveDataTable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d27da76
[PR#782] Remove support for case where the DataRow is descendant of a…
9rnsr 690c459
[PR#784] If DataTable is not present, DataRow provides equal widths t…
9rnsr 6c5aa0b
[PR#784] Add sample for the 'DataRow without DataTable' case
9rnsr 4c70613
[PR#786] Add internal methods in DataColumn
9rnsr 45ca1e5
[PR#786] Make DataColumn.DataTable property private
9rnsr ae539d6
Remove support for the 'Hybrid-case' that paring Grid and DataRows
9rnsr d62413f
Update the logic for the column widths calculation
9rnsr 35cccb5
fix non-fixed star column width measurement
9rnsr b5f8a30
Manual column resize should set DataColumn.IsFixed=true
9rnsr fcd3f5a
Merge branch 'main' into ImproveDataTable
Avid29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
components/DataTable/samples/DataRowWithoutDataTableSample.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using CommunityToolkit.WinUI.Controls; | ||
|
|
||
| namespace DataTableExperiment.Samples; | ||
|
|
||
| [ToolkitSample(id: nameof(DataRowWithoutDataTableSample), "DataRows without DataTable Example", description: $"A sample for showing the default layout of {nameof(DataRow)} withou {nameof(DataTable)} control.")] | ||
| public sealed partial class DataRowWithoutDataTableSample : Page | ||
| { | ||
| public const int NumberOfRows = 6; | ||
|
|
||
| public ObservableCollection<InventoryItem> InventoryItems { get; set; } | ||
|
|
||
| public DataRowWithoutDataTableSample() | ||
| { | ||
| InventoryItem[] items = new InventoryItem[NumberOfRows]; | ||
|
|
||
| for (int i = 0; i < NumberOfRows; i++) | ||
| { | ||
| items[i] = new() | ||
| { | ||
| Id = i, | ||
| Name = i.ToString(), | ||
| Description = i.ToString(), | ||
| Quantity = i, | ||
| }; | ||
| } | ||
|
|
||
| items[3].Name = "Hello, testing!"; | ||
|
|
||
| items[5].Description = "This is a very long description that should have been out of view at the start..."; | ||
|
|
||
| InventoryItems = new(items); | ||
|
|
||
| this.InitializeComponent(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
components/DataTable/samples/DataRowWithoutDataTableSample.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. --> | ||
| <Page x:Class="DataTableExperiment.Samples.DataRowWithoutDataTableSample" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors" | ||
| xmlns:controls="using:CommunityToolkit.WinUI.Controls" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:interactivity="using:Microsoft.Xaml.Interactivity" | ||
| xmlns:local="using:DataTableExperiment.Samples" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d"> | ||
|
|
||
| <ListView ItemsSource="{x:Bind InventoryItems}"> | ||
|
|
||
| <!-- no DataTable in <ListView.Header> --> | ||
|
|
||
| <ListView.ItemTemplate> | ||
| <DataTemplate x:DataType="local:InventoryItem"> | ||
| <controls:DataRow> | ||
| <TextBlock VerticalAlignment="Center" | ||
| Text="{x:Bind Id}" /> | ||
| <TextBlock VerticalAlignment="Center" | ||
| Text="{x:Bind Name}" /> | ||
| <TextBlock VerticalAlignment="Center" | ||
| Text="{x:Bind Description}" /> | ||
| <TextBlock VerticalAlignment="Center" | ||
| Text="{x:Bind Quantity}" /> | ||
| </controls:DataRow> | ||
| </DataTemplate> | ||
| </ListView.ItemTemplate> | ||
| </ListView> | ||
| </Page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
components/DataTable/samples/DataTableHybridSample.xaml.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,21 +10,34 @@ namespace CommunityToolkit.WinUI.Controls; | |||||
| [TemplatePart(Name = nameof(PART_ColumnSizer), Type = typeof(ContentSizer))] | ||||||
| public partial class DataColumn : ContentControl | ||||||
| { | ||||||
| private static GridLength StarLength = new GridLength(1, GridUnitType.Star); | ||||||
|
|
||||||
| private ContentSizer? PART_ColumnSizer; | ||||||
|
|
||||||
| private WeakReference<DataTable>? _parent; | ||||||
|
|
||||||
| // Pass-thru convenience helper to get reference from WeakReference; computed each time, do not store result! | ||||||
| private DataTable? DataTable => _parent?.TryGetTarget(out DataTable? parent) == true ? parent : null; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the internal calculated or manually set width of this column. | ||||||
| /// NaN means that the column size is no yet calculated. | ||||||
| /// </summary> | ||||||
| internal double CurrentWidth { get; set; } = double.NaN; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the width of the largest child contained within the visible <see cref="DataRow"/>s of the <see cref="DataTable"/>. | ||||||
| /// Gets the internal calculated or manually set width of this column, as a positive value. | ||||||
| /// </summary> | ||||||
| internal double MaxChildDesiredWidth { get; set; } | ||||||
| internal double ActualCurrentWidth => double.IsNaN(CurrentWidth) ? 0 : CurrentWidth; | ||||||
|
|
||||||
| internal bool IsAbsolute => DesiredWidth.IsAbsolute; | ||||||
|
|
||||||
| internal bool IsAuto => DesiredWidth.IsAuto; | ||||||
|
|
||||||
| internal bool IsStar => DesiredWidth.IsStar; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the internal copy of the <see cref="DesiredWidth"/> property to be used in calculations, this gets manipulated in Auto-Size mode. | ||||||
| /// Returns <see langword="true"/> if the column width is fixed with the manual adjustment. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is a more standard property comment format |
||||||
| /// </summary> | ||||||
| internal GridLength CurrentWidth { get; private set; } | ||||||
| internal bool IsFixed { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets whether the column can be resized by the user. | ||||||
|
|
@@ -58,10 +71,29 @@ public GridLength DesiredWidth | |||||
|
|
||||||
| private static void DesiredWidth_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||||||
| { | ||||||
| // If the developer updates the size of the column, update our internal copy | ||||||
| if (d is DataColumn col) | ||||||
| // If the developer updates the size of the column, update our internal value. | ||||||
| if (d is DataColumn column) | ||||||
| { | ||||||
| col.CurrentWidth = col.DesiredWidth; | ||||||
| if (column.DesiredWidth is { GridUnitType: GridUnitType.Pixel, Value: var value }) | ||||||
| { | ||||||
| column.IsFixed = true; | ||||||
| column.CurrentWidth = value; | ||||||
| } | ||||||
| else if (column.DesiredWidth is { GridUnitType: GridUnitType.Star, Value: 0 }) | ||||||
| { | ||||||
| // Handle DesiredWidth="0*" as fixed zero width column. | ||||||
| column.IsFixed = true; | ||||||
| column.CurrentWidth = 0; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| // Reset the manual adjusted width. | ||||||
| column.IsFixed = false; | ||||||
| column.CurrentWidth = double.NaN; | ||||||
| } | ||||||
|
|
||||||
| // Request to measure for the IsAutoFit or IsStarProportion columns. | ||||||
| column.DataTable?.InvalidateMeasure(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -115,13 +147,10 @@ private void PART_ColumnSizer_ManipulationCompleted(object sender, ManipulationC | |||||
| private void ColumnResizedByUserSizer() | ||||||
| { | ||||||
| // Update our internal representation to be our size now as a fixed value. | ||||||
| CurrentWidth = new(this.ActualWidth); | ||||||
| CurrentWidth = this.ActualWidth; | ||||||
| IsFixed = true; | ||||||
|
|
||||||
| // Notify the rest of the table to update | ||||||
| if (_parent?.TryGetTarget(out DataTable? parent) == true | ||||||
| && parent != null) | ||||||
| { | ||||||
| parent.ColumnResized(); | ||||||
| } | ||||||
| DataTable?.ColumnResized(); | ||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this. The implication that the current width can ever be negative seems like a design flaw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? This value can never be negative; it will always be either
NaNor a positive value.