Reputation: 31
I would like to manually set DataGridCell´s DataContext over styles like this:
<Style TargetType="DataGridCell" x:Key="DynamicGridCellStyle">
<Setter Property="DataContext" Value="{x:Null}"/>
</Style>
Then in other place I am setting cell style for all cells in column:
<DataGridTemplateColumn
csdpp:CalendarProperties.EnumDay="Tue"
HeaderStyle="{StaticResource DayHeaderStyle}"
CellStyle="{StaticResource DynamicGridCellStyle}">
</DataGridTemplateColumn>
In real there is not x:Null, but some binding, but it doesnt matter, problem remains with x:Null too.
Problem is: after this is called at start, DataGridCell´s DataContexts are different then null. Something is just changing them.
Is there any way how to catch what? I was looking for DataContextChanged event, but that leads just to next heavy code. Or how is that even possible? I have DataGridCell inside DataGrid connected to CollectionViewSource, could be problem there? Could CollectionViewSource change DataGridCell DataContext?
Upvotes: 1
Views: 671
Reputation: 31
In the end I solved this by adding attached dependency property to DataGridCell to store custom data objects. This solution allows me to use DataGridCell DataContext inherited from parents too.
Upvotes: 0