WPF DataGrid RowHeader databinding

前端 未结 6 2085
孤城傲影
孤城傲影 2020-12-05 13:17

I have a DataGrid, bound to a DataTable. I want to display text in the RowHeader, to achieve something like this:

         Col0      Col1      Col2      Col3         


        
6条回答
  •  无人及你
    2020-12-05 13:50

    I tried both answers, and neither worked for me. Essentially what I had to do was mix them together.

    This works for me:

    
            
        
    
    

    The trick is to find the ancestor DataGridRow, then Bind the TextBlock.Text attribute to its Item's property that you care about, in this case Header (easier said in XAML than English maybe).

    Then in the .xaml.cs:

    ui_dataGrid.ItemsSource = dataSource.Rows;
    

    N.B. Each Row object has a Header property which is what I'm binding too.

提交回复
热议问题