How to set the DataContext on a DataGrid Column Header

后端 未结 3 879
天命终不由人
天命终不由人 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:46

    Turns out that one can use the Header property (which is of type Object) as the DataContext for the DataTemplate (set as shown above):

    Style headerStyle = (Style)Resources["ColumnHeaderStyle"];
    DataGridTextColumn col = new DataGridTextColumn();
    col.HeaderStyle = headerStyle;
    col.Header = myHeaderDataContext; // DataContext for ColumnHeaderStyle
    dataGrid.Columns.Add(col);
    

提交回复
热议问题