C# 如何冻结 WPF DataGrid 的第一列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18546559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Freeze First Column of WPF DataGrid
提问by Avinash Singh
I have a WPF DataGrid..
我有一个 WPF DataGrid ..
I want to freeze first column of that WPF DataGrid while horizontal scrlling..
我想在水平滚动时冻结该 WPF DataGrid 的第一列。
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>
采纳答案by Kurubaran
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.
冻结列是始终显示且无法滚动到可见范围之外的列。冻结列始终是显示顺序中最左边的列。您不能将冻结列拖入未冻结列组或将未冻结列拖入冻结列组。