我有一个GridView控件,我正在添加GridView列。我之前使用了GridViewColumn的DisplayMemberBinding属性,但现在我想使用CellTemplate。我正在绑定一个字典。
下面的代码在使用DisplayMemberBinding时有效:
var column = new GridViewColumn
{
Header = current.Key,
DisplayMemberBinding = new Binding("[" + current.Key + ]")
};
现在,我需要对CellTemplate做同样的操作,但出于某些原因,我不确定为什么它没有显示项目。
var column = new GridViewColumn
{
Header = current.Key,
CellTemplate = (DataTemplate)FindResource("GridViewTextBlockDataTemplate"),
};
以下是在Window.Resources中定义的DataTemplate:
<DataTemplate x:Key="GridViewTextBlockDataTemplate" x:Name="GridViewTextBlockDataTemplate">
<TextBlock Text="{Binding Path=[Key]}"></TextBlock>
</DataTemplate>
谢谢,Azam。