How can I freeze my column header in a DataGrid
in my WPF
Window so that when I scroll down, the header is still visible.
[Edit]
Here's my XAML
:
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Visible">
<DataGrid Name="ModelsGrid" Background="Transparent" Foreground="Black" RowHeight="30" ColumnWidth="100" AutoGenerateColumns="False" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Property ID" Binding="{Binding Path=Id}" />
<DataGridTextColumn Header="Name" Width="Auto" Binding="{Binding Path=PropertyName}" />
<DataGridTextColumn Header="Description" Width="Auto" Binding="{Binding Path=Description}" />
<DataGridTextColumn Header="Access" Width="Auto" Binding="{Binding Path=Accessibility}" />
<DataGridTextColumn Header="Type" Width="Auto" Binding="{Binding Path=Type}" />
<DataGridTextColumn Header="Category" Width="Auto" Binding="{Binding Path=Category}" />
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
[Edit]
I just had to get rid of the ScrollViewer
and it's solved.
Set the Datagrid's FrozenColumnCount = "1". Frozen columns are columns that are always displayed and cannot be scrolled out of visibility. Frozen columns are always the leftmost columns in display order. You cannot drag frozen columns into the group of unfrozen columns or drag unfrozen columns into the group of frozen columns.
EDIT: To clarify, it will still need to be the first column that is frozen, but it'll be frozen to the right side. Sorry, something went wrong. Sorry, something went wrong. I tried this alternative solution you have mentioned @miloush . Last column can be freezed.But then so many other issues are rising compared to normal WPF data-grid behavior.
The frozen columns stay static on top of the horizontal scrolling. To freeze a column on the left, the user has to drag the left frozen columns separator. Once there is a frozen column, you can freeze other columns by dragging their headers behind the frozen columns separator.
To disable the freezing of a column, just set the CanUserFreezeColumns to False (as shown in Example 2) and the frozen columns separator will disappear. You can set the FrozenColumnsSplitterVisibility property of the RadGridView control in order to hide/show the left frozen columns splitter.
I just had to get rid of the ScrollViewer and it's solved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With