嗨,我有一个数据网格,它有许多相同的 datagridtemplate 列,除了它们在模板的堆栈面板上都有不同的数据上下文。
<toolkit:DataGridTemplateColumn Header="Col 1">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel DataContext="{Binding Times[0]}">
<!-- the structure that I want to extract to a template -->
</StackPanel>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>
<toolkit:DataGridTemplateColumn Header="Col 2">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel DataContext="{Binding Times[1]}">
<!-- the same structure here -->
</StackPanel>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>
我想让每一列都使用一个特定的项目模板(就像我对列表框所做的那样),但除非我遗漏了一些东西,否则我似乎看不到如何做。