C# Wpf datagridcell datacontext不会保留

C# Wpf datagridcell datacontext不会保留,c#,wpf,datagridcell,C#,Wpf,Datagridcell,我想手动设置DataGridCell的DataContext样式,如下所示: <Style TargetType="DataGridCell" x:Key="DynamicGridCellStyle"> <Setter Property="DataContext" Value="{x:Null}"/> </Style> 然后在另一个地方,我为列中的所有单元格设置单元格样式: <DataGridTemplateColum

我想手动设置DataGridCell的DataContext样式,如下所示:

<Style TargetType="DataGridCell" x:Key="DynamicGridCellStyle">               
<Setter Property="DataContext" Value="{x:Null}"/>
</Style>

然后在另一个地方,我为列中的所有单元格设置单元格样式:

<DataGridTemplateColumn 
csdpp:CalendarProperties.EnumDay="Tue"
HeaderStyle="{StaticResource DayHeaderStyle}"
CellStyle="{StaticResource DynamicGridCellStyle}">
</DataGridTemplateColumn>

在现实中并没有x:Null,而是一些绑定,但这并不重要,问题仍然存在于x:Null

问题是:在开始调用该函数后,DataGridCell的DataContext与null不同。有些事情正在改变他们


有没有办法抓住什么?我正在寻找DataContextChanged事件,但这只会导致下一个繁重的代码。或者这怎么可能呢?我在DataGrid中有DataGridCell连接到CollectionViewSource,可能有问题吗?CollectionViewSource能否更改DataGridCell DataContext?

最后,我通过向DataGridCell添加附加的依赖项属性来存储自定义数据对象,从而解决了这个问题。这个解决方案允许我使用从父代继承的DataGridCell DataContext