WPF:带有“索引”列的GridView

时间:2010-02-09 18:25:08

标签: c# wpf gridview listview

我有ListView的标准GridView。现在我希望GridView中的一列成为列表中该行的从1开始的索引,如下所示:

| # | First name | Last name |
| 1 | John       | Smith     |
| 2 | Anne       | Anderson  |

我该怎么做?

1 个答案:

答案 0 :(得分:1)

忘了回答这个,因为列是静态的,你可以创建一个ItemSource绑定到数组或任何持有项目。

<GridView ItemSource="{Binding ArrayName}" 
          ItemTemplate="{StaticResource gridViewTemplates}" 
          Name="Whatever" ...>
</GridView>

现在我们必须设置模板

<DataTemplate x:Key="gridViewTemplates">
    <TextBlock Row="{Binding RowNumber}" Column="0" Name="Id" 
           Text={"Binding Id"} />
</DataTemplate>

请对您最适合的事情进行更改。

this tutorial上的更多信息。

相关问题