我有DataGrid
,当我不希望用户更改任何内容时,我当前设置为ReadOnly
,然后我有一个按钮供用户单击以允许修改,然后将IsReadOnly
更改为false
但现在问题是当DataGrid.IsReadOnly = true
时,滚动被禁用。如何设置DataGrid IsReadOnly=true
或类似网格,并且仍能滚动DataGrid
?
DataGrid风格:
<DataGrid.Style>
<Style TargetType="{x:Type DataGrid}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ReadOnly}" Value="True"/>
<Condition Binding="{Binding Reordering}" Value="False"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Foreground" Value="Gray" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ReadOnly}" Value="True"/>
<Condition Binding="{Binding Reordering}" Value="True"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="IsReadOnly" Value="True" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ReadOnly}" Value="False"/>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsHitTestVisible" Value="True" />
<Setter Property="IsReadOnly" Value="False" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Style>
答案 0 :(得分:0)
你试过这个:
dataGridView1.ReadOnly = true;
void dataGridView1_DoubleClick(object sender, EventArgs e)
{
if (dataGridView1.ReadOnly == true)
return;
// .. whatever code you have in your handler...
}