How to set the DataContext on a DataGrid Column Header

后端 未结 3 886
天命终不由人
天命终不由人 2020-12-15 12:58

In my Silverlight 3 user control I am showing a basic DataGrid control. I need to generate the columns programmatically as

3条回答
  •  忘掉有多难
    2020-12-15 13:47

    Based on Matt's answer, I came up with the solution of binding the header on the DataGridCellsPanel which in Snoop appeared to have the correct data context :

      
         
      
    

    And this is non intrusive in the way that you can still inherits from custom styled headers (see exemple above) or event the base column header style:

     
         
     
    

    This solution has the advantage of being pure and clean XAML and to refer to the closest ancestor holding the correct datacontext rather than trying to reach datacontext of top hierarchy elements like UserControl.

提交回复
热议问题