猿问

DataGrid isReadyOnly 无法正常工作

我有一个 dataGridisReadOnly设置为true. 在那个数据网格中,我有多个列(DataGridTemplateColumn),我面临的问题是这个:


<DataGridTemplateColumn IsReadOnly="True" SortMemberPath="OnVacation" Header="En vacance" >                                               <DataGridTemplateColumn.CellTemplate>

    <DataTemplate>

<CheckBox  VerticalAlignment="Center"  IsChecked="{Binding Path=OnVacation, Mode=TwoWay}"  />

    </DataTemplate>

  </DataGridTemplateColumn.CellTemplate>

</DataGridTemplateColumn>

我还设置sReadyOnly了列本身(如您在上面看到的),但这没有做任何事情。我仍然可以选中/取消选中 CheckBox 并且它会改变。


冉冉说
浏览 328回答 1
1回答

慕哥9229398

如果您希望永久保留用户不可更改的复选框,则可以使用1. IsEnabled="假"<DataGridTemplateColumn IsReadOnly="True" SortMemberPath="OnVacation" Header="En vacance" >&nbsp;<DataGridTemplateColumn.CellTemplate>&nbsp; <DataTemplate>&nbsp; &nbsp;<CheckBox&nbsp; VerticalAlignment="Center"&nbsp; IsChecked="{Binding Path=OnVacation,&nbsp;&nbsp; &nbsp;Mode=TwoWay}" IsEnabled="False"&nbsp; />&nbsp; </DataTemplate>&nbsp;</DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>2. IsHitTestVisible="假"<DataGridTemplateColumn IsReadOnly="True" SortMemberPath="OnVacation" Header="En vacance">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DataGridTemplateColumn.CellTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DataTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <CheckBox&nbsp; VerticalAlignment="Center"&nbsp; IsChecked="{Binding Path=OnVacation, Mode=TwoWay}" IsHitTestVisible="False">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </CheckBox>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataGridTemplateColumn.CellTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataGridTemplateColumn>
随时随地看视频慕课网APP
我要回答