Skip to content

Provide suitable DataRow behavior when DataTable is not present#784

Open
9rnsr wants to merge 2 commits intoCommunityToolkit:mainfrom
9rnsr:ImproveDataTable-3
Open

Provide suitable DataRow behavior when DataTable is not present#784
9rnsr wants to merge 2 commits intoCommunityToolkit:mainfrom
9rnsr:ImproveDataTable-3

Conversation

@9rnsr
Copy link
Copy Markdown
Contributor

@9rnsr 9rnsr commented Feb 23, 2026

Separate PR from #781

This added behavior just covers a corner case. If a user fails to place corresponding DataTable at correct position, displaying somethings is better than nothing.

Each rows layout their columns independent, because there's no main controller to remember the column widths, and then it looks like a horizontal StackPanel.
If there's no main controller to remember the column widths, each DataRow uses the full width of its parent element to provide equal widths to its child elements.

@9rnsr 9rnsr force-pushed the ImproveDataTable-3 branch 2 times, most recently from 3933681 to 371b6d9 Compare April 25, 2026 01:12
@michael-hawker
Copy link
Copy Markdown
Member

Was thinking about this scenario a bit more over the weekend, and I see a couple of directions:

  1. If they just have a DataRow it's better to just have another panel there instead if they don't intend to use it as it's intended. Providing another behavior may be confusing or not lead them to understanding that there's more to be done. Probably something to think about if we can indicate this different state another way.

  2. If we did want a default behavior. Probably doing a more EqualPanel type behavior where we space each item out based on the available width / number of items would make more sense, as then as long as the developer has the same number of items in each row (which they would with a data template) then it evenly spaces each item and maintains columns between the rows compared to them being jagged.

@9rnsr
Copy link
Copy Markdown
Contributor Author

9rnsr commented Apr 29, 2026

The jagged layout of each row is exactly what I intended, because it can strongly recommend that the DataRow control is being used incorrectly.

…But, as you pointed out, there’s less real practical benefit to that behavior, and I can admit that your idea is more practical. I’ll update the default behavior so that each child element in the DataRow is given an equal width.

9rnsr added 2 commits April 29, 2026 14:19
…ld elements

This added behavior just covers a corner case. If a user fails to place corresponding DataTable at correct position, displaying somethings is better than nothing.

If there's no main controller to remember the column widths, each DataRow uses the full width of its parent element to provide equal widths to its child elements.
@9rnsr 9rnsr force-pushed the ImproveDataTable-3 branch from 371b6d9 to 0bff904 Compare April 29, 2026 05:19
@9rnsr 9rnsr changed the title DataRow lay out children like a horizontal StackPanel if DataTable is not present Provide suitable DataRow behavior when DataTable is not present Apr 29, 2026
@9rnsr
Copy link
Copy Markdown
Contributor Author

9rnsr commented Apr 29, 2026

Updated. To check the new DataRow behavior, I added a sample.

Copy link
Copy Markdown
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few small comments. @niels9001 any thoughts on this as a default partial behavior?

return new Size(0, finalSize.Height);

double x = 0;
double width = finalSize.Width / Children.Count;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the visible child count here otherwise we'll make everything smaller and not take up the full width, we can cache this from the measure step.


if (Children.Count > 0)
// If we don't have a grid, provides equal widths to child elements.
if (_parentPanel is null)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both the measure and arrange bit we should probably abstract these to sub-methods to just make it a bit easier to contain.


<!-- no DataTable in <ListView.Header> -->

<ListView.ItemTemplate>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample is nice here thanks, this does seem like a useful base scenario, though someone could just use an EqualPanel here just as easily, it does extend itself later to just adding the rest of the pattern if needed.

Comment on lines +31 to +36
<!--<ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource DefaultListViewItemStyle}"
TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</ListView.ItemContainerStyle>-->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded?

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.

2 participants