fix(DataGrid): Center DataGridCell-Content by default - #4087
Merged
Conversation
Member
Author
|
this was partially addressed in PR #4069. However, the style did not define a default value for <Setter Property="VerticalContentAlignment" Value="Center" /> |
Keboo
approved these changes
Sep 4, 2026
Keboo
enabled auto-merge (squash)
September 4, 2026 04:56
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fixes #3999
Problem
MaterialDesignDataGridCell'sControlTemplatedoesn't forwardHorizontalContentAlignment/VerticalContentAlignmentto itsContentPresenter, so setting those properties has no effect. As a workaround, users setVerticalAlignment="Center"on the cell itself instead:This centers the cell itself rather than its content - so when
RowHeightis taller than the cell's desired height, the cell no longer stretches to fill the row. That leaves a gap above and below each cell, which appears as duplicate horizontal gridlines whenGridLinesVisibilityincludesHorizontal.Fix
Bind
HorizontalAlignment/VerticalAlignmenton theContentPresentertoHorizontalContentAlignment/VerticalContentAlignmentviaTemplateBinding. With that in place,VerticalContentAlignment="Center"centers the content while the cell itself still stretches to fill the row, so there's no gap and no duplicate gridlines.Testing
I wasn't sure how to reasonably cover this with an automated test, so I added an example to the demo app instead. Happy to open a follow-up PR to bring this example into the MD3 demo app and consolidate view models.
Current default behavior
Current default behavior with the
DataGridCellstyle below appliedNew default behavior