0

你们太有帮助了,我在绑定到列表视图时遇到了一些麻烦,想知道是否有人可以帮助我,这是我的代码。

这是xaml

    <ListView Name="ListView" Margin="0,0,16,145" ItemsSource="{Binding EmailCollection}" AllowDrop="True" HorizontalAlignment="right" Width="704" IsEnabled="True" Background="White" Foreground="Black" BorderBrush="#FF313131">

        <ListView.View>
            <GridView>

                <GridViewColumn DisplayMemberBinding="{Binding Pic}"  Width="140" Header="Picture"/>
                <GridViewColumn DisplayMemberBinding="{Binding Person}" Width="140" Header="Person" />
                <GridViewColumn  DisplayMemberBinding="{Binding Email}" Width="200" Header="Email" />
                <GridViewColumn  DisplayMemberBinding="{Binding Location}" Width="160" Header="Location" />
                <GridViewColumn  DisplayMemberBinding="{Binding Age}" Width="50" Header="Age" />
            </GridView>
        </ListView.View>
    </ListView>

在这里,我试图向 person 列添加一个项目,但它说 system.windows.controls.listviewitem 不包含 person 的定义,也许我遗漏了什么?

    ListView.Items.Add(new ListViewItem {Person = t.InnerHtml});
4

1 回答 1

1

如果 ListView 绑定到项目集合,那么您不能直接添加到它。相反,请执行以下操作:

  1. 确保EmailCollection是类型ObservableCollection
  2. 将新项目直接添加到源EmailCollection
于 2012-08-24T04:17:57.907 回答