WPF DataGrid: Frozen Row Sample

It looks that this is a frequently requested feature and unfortunately didn't make the v1.  It is still possible to extend the DataGrid to do so.  A community developer has already posted a sample on creating a footer row for the DataGrid here, http://thibaud60.blogspot.com/2008/10/wpftoolkit-datagrid-with-footer-and.html.  I thought I would post a sample for creating pinned rows starting from the top.  This is similar to the excel pinning functionality. 

I won't really go into too much implementation detail but I basically follow a similar pattern to the way frozen columns are implemented.  The core of the code is in a CustomDataGridRowsPresenter.ArrangeOverride method.  I tried to make it as simple as possible so it could be easily understood and as a result of that I didn't implement virtualization.  Well, that's part of the reason I didn't implement virtualization.  VirtualizingStackPanel isn't very extendable when it comes to it's virtualization and recycling functionality.  I would have to do a good bit of my own implementation for it and it would take a good bit of time.  So, the sample only works when row and column virtualization is turned off.  If anyone feels up to making it work with virtualization, please be my guest. = ) 

Anyway, you can download the sample here.  On the left pane I added buttons to increase/decrease the frozen row and column counts. 

Note: The purpose of the sample is for learning purposes only.  Please do not use this in production code as it is not fully tested.


Comments (5)

  1. Huy says:

    How to I frozen bottom to top?

    So I can lock the last row in the Data Grid?

  2. UPDATE: the WPF DataGrid v1 has just released. For more information, see this post . The information

  3. Thibaud says:


    I just try another approach here


    Instead of modifying the DataGrid component and its template, I associate it between multiple instances

    It is just an idea and a simple demo, but It’s seems pretty nice and work with WPF 4.0 Datagrid version !

  4. Karthika says:

    Hi Vincent,

        I tried the code in a sample custom datagrid. It works perfectly when we set the height og datagrid to some value. If we set the height to Auto means some row gets disappear…Any idea on this?

Skip to main content