I have a data grid column that requires the VirtualizationMode to be "Standard", not "Recycling". Therefore I would like to set this property in the DataGrid automatically.
The problem is that in the constructor of my column the DataGridOwner is not yet set (and is null) and in GenerateElement override it is too late for changing VirtualizationMode, as the layout is already there and measured (== throws exception at runtime).
Just for clarity:
public class MyDataGridColumn : DataGridTextColumn
{
public MyDataGridColumn() : base()
{
// DataGridOwner property is null at this point
}
protected override FrameworkElement GenerateElement(
DataGridCell cell,
object dataItem)
{
// I tried setting the VirtualizationMode here, yet runtime exception
// says that the layout is measured and mode can't be changed
}
}
Is there any way to accomplish this without changing the default style of the DataGrid? Can I set this property using my column's style? Any other suggestions?