Why is the ComboBox in that column only visible via double-click in the empty cell when the DataGrid is set to IsReadOnly = FALSE ???
当DataGrid设置为IsReadOnly = FALSE时,为什么只有通过双击空单元格才能看到该列中的ComboBox?
<DataGridComboBoxColumn Width="*" IsReadOnly="False" Header="test" />
using a DataTemplateColumn works as always... whats wrong with that DataGridComboBoxColumn?
使用DataTemplateColumn一如既往地工作...... DataGridComboBoxColumn有什么问题?
works:
<DataGridTemplateColumn Header="Schoolclass">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Background="Blue" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
1 个解决方案
#1
10
All builtin DataGridColumns have two styles. One for when the cell is not in editing mode and one where the cell is in editing mode. Usually the non editing mode simply displays a textblock, not the actual control you might expect (ComboBox, TextBox, etc). And once you start editing the cell, the textblock is replaced with the appropriate control. If you have the datagrid set to IsReadOnly = true, then that means the cells never go to their editing mode and that is the behaviour you are seeing.
所有内置的DataGridColumns都有两种样式。一个用于单元格未处于编辑模式,另一个单元格处于编辑模式。通常,非编辑模式只显示一个文本块,而不是您可能期望的实际控件(ComboBox,TextBox等)。一旦开始编辑单元格,文本块就会被适当的控件替换。如果您将datagrid设置为IsReadOnly = true,那么这意味着单元格永远不会进入编辑模式,这就是您所看到的行为。
When creating a DataGridTemplateColumn you are essentialy replacing all the built in datagrid logic. As an example if you want your templated column to be readonly when the datagrid is readonly, then you have to manually bind the two values together. And if you wanted to get the same behaviour as the builtin columns (textblock when cell is not in editing mode), then you'd have to use triggers to supply the appropriate controltemplates.
在创建DataGridTemplateColumn时,您必须替换所有内置的datagrid逻辑。例如,如果您希望在数据网格只读时您的模板化列是只读的,那么您必须手动将这两个值绑定在一起。如果你想获得与内置列相同的行为(单元格未处于编辑模式时的文本块),那么你必须使用触发器来提供适当的控制模板。
Also note, that if you are using a built in column (eg DataGridCheckBoxColumn) and you speficy an ElmentStyle for it (for instance to center the checkBoxes) then the column's cells are all editable despite datagrid being set to IsReadOnly = true. This happens because when you specify an ElmentStyle you are replacing the builtin Style, which contains logic to make the checkboxes readonly when the datagrid is readonly.
另请注意,如果您使用内置列(例如DataGridCheckBoxColumn)并为其设置ElmentStyle(例如使checkBoxes居中),则尽管datagrid设置为IsReadOnly = true,但列的单元格都是可编辑的。发生这种情况是因为当您指定ElmentStyle时,您正在替换内置样式,该样式包含在数据网格只读时使复选框只读的逻辑。
#1
10
All builtin DataGridColumns have two styles. One for when the cell is not in editing mode and one where the cell is in editing mode. Usually the non editing mode simply displays a textblock, not the actual control you might expect (ComboBox, TextBox, etc). And once you start editing the cell, the textblock is replaced with the appropriate control. If you have the datagrid set to IsReadOnly = true, then that means the cells never go to their editing mode and that is the behaviour you are seeing.
所有内置的DataGridColumns都有两种样式。一个用于单元格未处于编辑模式,另一个单元格处于编辑模式。通常,非编辑模式只显示一个文本块,而不是您可能期望的实际控件(ComboBox,TextBox等)。一旦开始编辑单元格,文本块就会被适当的控件替换。如果您将datagrid设置为IsReadOnly = true,那么这意味着单元格永远不会进入编辑模式,这就是您所看到的行为。
When creating a DataGridTemplateColumn you are essentialy replacing all the built in datagrid logic. As an example if you want your templated column to be readonly when the datagrid is readonly, then you have to manually bind the two values together. And if you wanted to get the same behaviour as the builtin columns (textblock when cell is not in editing mode), then you'd have to use triggers to supply the appropriate controltemplates.
在创建DataGridTemplateColumn时,您必须替换所有内置的datagrid逻辑。例如,如果您希望在数据网格只读时您的模板化列是只读的,那么您必须手动将这两个值绑定在一起。如果你想获得与内置列相同的行为(单元格未处于编辑模式时的文本块),那么你必须使用触发器来提供适当的控制模板。
Also note, that if you are using a built in column (eg DataGridCheckBoxColumn) and you speficy an ElmentStyle for it (for instance to center the checkBoxes) then the column's cells are all editable despite datagrid being set to IsReadOnly = true. This happens because when you specify an ElmentStyle you are replacing the builtin Style, which contains logic to make the checkboxes readonly when the datagrid is readonly.
另请注意,如果您使用内置列(例如DataGridCheckBoxColumn)并为其设置ElmentStyle(例如使checkBoxes居中),则尽管datagrid设置为IsReadOnly = true,但列的单元格都是可编辑的。发生这种情况是因为当您指定ElmentStyle时,您正在替换内置样式,该样式包含在数据网格只读时使复选框只读的逻辑。