繁体   English   中英

WPF:带有“索引”列的GridView

[英]WPF: GridView with an “index” column

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

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

我怎么做?

忘了回答这一问题,因为列是静态的,所以您可以创建一个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>

请做出最适合您的更改。

有关本教程的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM