【问题标题】:Wpf datagridcell datacontext wont remainWpf datagridcell datacontext不会保留
【发布时间】:2014-08-27 15:35:51
【问题描述】:

我想通过以下样式手动设置 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 也有问题。

问题是:在启动时调用 this 后,DataGridCell 的 DataContexts 与 null 不同。有些东西正在改变他们。

有什么办法可以捕捉到什么吗?我一直在寻找 DataContextChanged 事件,但这只会导致下一个繁重的代码。或者这怎么可能?我在 DataGrid 中有连接到 CollectionViewSource 的 DataGridCell,那里可能有问题吗? CollectionViewSource 可以改变 DataGridCell DataContext 吗?

【问题讨论】:

    标签: c# wpf datagridcell


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      相关资源
      最近更新 更多