我希望在 WPF 数据网格中有一个自定义列类型,其中一部分将是用户输入的文本框。Unfortunately, it does not appear to inherit the look and feel of the datagrid itself- it doesn't show the alternating colour, when a row is selected or edited the cell in question doesn't highlight in the same way, and so on.
<DataGridTemplateColumn Header="Name" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<TextBox Text="{Binding DisplayName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" BorderThickness="0" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
看起来默认文本框的样式覆盖了数据网格的样式;有没有办法只使用数据网格样式?我当然可以设置文本框的样式来模仿数据网格,但是如果我想添加其他控件,我也必须为每个控件都这样做。如果我确实走这条路,我将如何根据单元格模板中的 datagridrow 的属性更改样式?-例如 IsSelected。