【问题标题】:WPF: GridView with an "index" columnWPF:带有“索引”列的 GridView
【发布时间】:2010-02-09 18:25:07
【问题描述】:

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

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

我该怎么做?

【问题讨论】:

标签: c# wpf gridview listview


【解决方案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的更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多