如何冻结WPF DataGrid的第一列[复制]

时间:2021-04-09 08:24:06

This question already has an answer here:

这个问题已经有了答案:

I have a WPF DataGrid..

我有一个WPF的数据集。

I want to freeze first column of that WPF DataGrid while horizontal scrlling..

我想在水平滚动的同时冻结WPF数据网格的第一列。

My code is:

我的代码是:

<DataGrid Name="dgQuestionTemplate" HorizontalAlignment="Left" Grid.Row="1" Width="870" HorizontalScrollBarVisibility="Auto" IsReadOnly="False">

            <DataGrid.Columns>                    
                <DataGridTextColumn Binding="{Binding ExamDate}" Header="Date" IsReadOnly="True" Width="90" />
                <DataGridTextColumn Binding="{Binding ExamName}" Header="Test Name" IsReadOnly="True" Width="195" />
                <DataGridTextColumn Binding="{Binding Batch}" Header="Batch" IsReadOnly="True" Width="100" />
                <DataGridTextColumn Binding="{Binding ExamTime}" Header="    Count Down  [Days: hr: min: sec]"  IsReadOnly="True" Width="*" />
            </DataGrid.Columns>

</DataGrid>

1 个解决方案

#1


38  

Set the Datagrid's FrozenColumnCount = "1".

设置Datagrid的FrozenColumnCount =“1”。

<DataGrid FrozenColumnCount ="1" Name="dgQuestionTemplate" HorizontalAlignment="Left" Grid.Row="1" Width="870" HorizontalScrollBarVisibility="Auto" IsReadOnly="False">

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.

冻结的列是始终显示的列,不能从可见性中滚动。在显示顺序中,冻结列总是最左边的列。不能将冻结的列拖到未冻结的列组中,也不能将未冻结的列拖到冻结的列组中。

DataGrid.FrozenColumnCount

DataGrid.FrozenColumnCount

#1


38  

Set the Datagrid's FrozenColumnCount = "1".

设置Datagrid的FrozenColumnCount =“1”。

<DataGrid FrozenColumnCount ="1" Name="dgQuestionTemplate" HorizontalAlignment="Left" Grid.Row="1" Width="870" HorizontalScrollBarVisibility="Auto" IsReadOnly="False">

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.

冻结的列是始终显示的列,不能从可见性中滚动。在显示顺序中,冻结列总是最左边的列。不能将冻结的列拖到未冻结的列组中,也不能将未冻结的列拖到冻结的列组中。

DataGrid.FrozenColumnCount

DataGrid.FrozenColumnCount