HI后动态更新WPF的ListView 我有这样的代码变化
private void Button_Click(object sender, RoutedEventArgs e)
{
ObservableCollection<ListProduct> myList = new ObservableCollection<ListProduct>();
int index = myList.IndexOf((from parcour in myList
where parcour.name == myProduct.name
select parcour).FirstOrDefault());
if(index != -1)
{
myList[index].number++;
}
}
public class ListProduct
{
public string name { get; set; }
public int number{ get; set; }
}
XAML:
<ListView Name="ListView12" ItemsSource="{Binding}" Height="201">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="name"
DisplayMemberBinding="{Binding name}" />
<GridViewColumn Width="100" Header="number"
DisplayMemberBinding="{Binding nombre}" />
</GridView>
</ListView.View>
</ListView>
这个片段是修改myListView 元素的occrnce的数量,当我点击该按钮,并使这些更改myListView不会改变。任何帮助请 - 是缺少的东西?
您在哪里将ListView的DataContext设置为集合。最好将ObservableCollection保留在Click处理程序之外 – 2010-03-07 00:10:16