How can I use CellsPanelHorizontalOffset in XAML?

Viewed 64

I want to define DataGrid.CellsPanelHorizontalOffset in XAML, how can I do it?

As far as I could understand I should define it by DataGridCellsPanel.

1 Answers

DataGrid.CellsPanelHorizontalOffset is a dependency property, which has public getter and private setter. So without reflection you will not be able to set this property directly.

BUT you can set it indirectly, if you set DataGrid.RowHeaderWidth. In most cases it will be the same, but not always (the value is based on some conditions and being calculated in DataGrid internally).

Folllowing example should force DataGrid.CellsPanelHorizontalOffset to return 0:

<DataGrid ItemsSource="..." RowHeaderWidth="0"></DataGrid>

and of course you can do bind to the DataGrid.CellsPanelHorizontalOffset:

<DataGrid x:Name="dg1" ItemsSource="..." RowHeaderWidth="100"></DataGrid>
<Label Background="DarkTurquoise" Width="{Binding ElementName=dg1, Path=CellsPanelHorizontalOffset}"/>
Related