[英]WPF: GridView with an “index” column
I have a standard ListView
with a GridView
. 我有一个带有
GridView
的标准ListView
。 Now I want one of the columns in the GridView
to be the 1-based index of that line in the list, as such: 现在,我希望
GridView
中的列之一成为列表中该行的从1开始的索引,如下所示:
| # | First name | Last name |
| 1 | John | Smith |
| 2 | Anne | Anderson |
How do I do that? 我怎么做?
Forgot to answer this one, since the columns are static, you can create an ItemSource binding to the array or whatever is holding the items. 忘了回答这一问题,因为列是静态的,所以您可以创建一个ItemSource绑定到数组或任何保存项目的对象。
<GridView ItemSource="{Binding ArrayName}"
ItemTemplate="{StaticResource gridViewTemplates}"
Name="Whatever" ...>
</GridView>
And now we have to set the template 现在我们必须设置模板
<DataTemplate x:Key="gridViewTemplates">
<TextBlock Row="{Binding RowNumber}" Column="0" Name="Id"
Text={"Binding Id"} />
</DataTemplate>
Please do the changes to whatever suits you best. 请做出最适合您的更改。
More Info on this tutorial . 有关本教程的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.