Hello,
I've set the DataGridHeaderStyle in the XAML-Code:
<DataGrid Name="dtgrd_contacts" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,73,0,27" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" AlternationCount="2" MouseDoubleClick="dtgrd_contacts_MouseDoubleClick"><DataGrid.ColumnHeaderStyle><Style TargetType="{x:Type DataGridColumnHeader}"><Setter Property="HorizontalContentAlignment" Value="Stretch" /></Style></DataGrid.ColumnHeaderStyle></DataGrid>
An this code is wrking fine...
But I need this code in the code behind and I have tried this:
DataGrid tmpDatagrid = dtgrd_contacts; Style tmpStyle = new Style(typeof(DataGridColumnHeader)); tmpStyle.Setters.Add(new Setter(DataGridColumnHeader.HorizontalAlignmentProperty, HorizontalAlignment.Stretch)); tmpDatagrid.ColumnHeaderStyle = tmpStyle;
But this code doesn't work and I have no idea why. In my opinion it should be the same as in the XAML-Code...
Please help me. What is wrong?
Thank you!