我想手动设置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的DataContexts不同于null。有些东西只是在改变它们。
有什么方法可以抓到什么吗?我一直在寻找DataContextChanged事件,但这只会导致下一个繁重的代码。或者这怎么可能呢?我让DataGridCell inside DataGrid连接到CollectionViewSource,会有问题吗?CollectionViewSource能改变DataGridCell DataContext吗?
发布于 2014-08-28 20:18:56
最后,我通过向DataGridCell添加附加的依赖属性来存储自定义数据对象,从而解决了这个问题。这个解决方案让我也可以使用从父母那里继承的DataGridCell DataContext。
https://stackoverflow.com/questions/25531368
复制相似问题