can i freeze the First top row of datagrid in wpf ?
I have created data grid in XAML page with a header which is by default in freeze mode and i have one more row which needs to show as header only to the user for that I am trying to freeze the row. If I want to freeze the column of data grid I am able to do but when the case comes for freezing the top row of data grid I failed to do.
Sandhiya PriyaPosted Oct 29, 2025, 10:20 AM
it’s a common confusion point in WPF DataGrid, because while you can easily freeze columns (using
FrozenColumnCount), freezing rows isn’t natively supported out-of-the-box in WPF’sDataGrid.Let’s break this down clearly
Problem
You want to:
Keep the built-in column headers (already frozen ),
AND freeze one more custom top row (like a secondary header or summary row)
— so that this row stays visible even when scrolling vertically.
Limitation
In WPF’s
DataGrid, there is no direct property likeFrozenRowCount.You can only freeze columns, not rows.
But — we can achieve the same effect with a UI layout trick.
Workaround: Use Two DataGrids in a Grid Layout
You can place two DataGrids (or one
DataGrid+ oneGrid) —the top one for your "frozen row", and the bottom one scrollable.
Example
Explanation:
The top DataGrid (or even a simple
GridorStackPanel) holds the “frozen” top row data.The bottom DataGrid scrolls normally.
The two can have identical columns to appear seamless.
To make them scroll horizontally together, you can synchronize the scrollbars via event binding in code-behind.
Optional Enhancement – Sync Horizontal Scroll
In code-behind:
You’d need to get the internal
ScrollViewerof each DataGrid (can useVisualTreeHelper).Alternative Approach – Use a Custom Template
If you really want everything in a single
DataGrid, you can define a frozen summary row in the DataGrid’s template (via aGridoverlay), but that’s complex and doesn’t work well with virtualization or scrolling.So the two-DataGrid layout is the most reliable, professional way.
Summary