我有一个列表视图,在第一列我尝试绑定基础集合的索引。
<Window.Resources>
<local:IndexConverter x:Key="IndexConverter" />
</Window.Resources>
....
<ListView>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Width="70" Height="40"
Content="{Binding RelativeSource={RelativeSource AncestorType=ListViewItem}, Converter={StaticResource IndexConverter}}"></Label>
<!-- More stuff -->
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
// IndexConverter
public object Convert(object value, Type TargetType, object parameter, CultureInfo culture)
{
// Get row number. This part is working.
// Return the formatted row number
return string.Format("#{0}", rowNumber);
}
当我编译这个我得到以下错误:
属性“内容”不能是绑定到可视元素的数据。
绑定有什么问题?