WPF DataGrid:使单元格只读
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2503078/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:36:38 来源:igfitidea点击:
WPF DataGrid: Make cells readonly
提问by crauscher
I use the following DataGrid
我使用以下 DataGrid
<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="100" Binding="{Binding Path=Name}"></DataGridTextColumn>
<DataGridTextColumn Header="OldValue" Width="100" Binding="{Binding Path=OldValue}"></DataGridTextColumn>
<DataGridTextColumn Header="NewValue" Width="100*" Binding="{Binding Path=NewValue}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
How can I make the cells readonly?
如何使单元格只读?
回答by Taylor Leese
Set DataGrid's IsReadOnlyproperty to true.
将 DataGrid 的IsReadOnly属性设置为 true。
<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}"
IsReadOnly="True" AutoGenerateColumns="False" >
回答by Parisa
If you want to make the cells of a certain columnreadonly, you can set IsReadOnly for that column:
如果要使某一列的单元格只读,可以为该列设置 IsReadOnly:
<DataGridTextColumn Header="Name" IsReadOnly="True" Width="100" Binding="{Binding Path=Name}"></DataGridTextColumn>
回答by Tony Orphanson
<DataGrid x:Name="dgUsers"
...
$dgUsers = $Form.FindName("dgUsers")
....
# Make all columns cells readonly
$dgUsers.Columns | ForEach-Object { $_.IsReadOnly = $True }