【发布时间】:2013-04-04 13:02:55
【问题描述】:
需要一些帮助,当我单击 tap_event 时,我得到一个消息框删除或取消哪个有效,价格从总价中扣除,但之后它不更新购物车,它在“ListBoxCart.Items.Remove”上崩溃(curr),提前谢谢!
private void listBoxCart_Tap(object sender, GestureEventArgs e)
{
if (MessageBox.Show("Are you sure!", "Delete", MessageBoxButton.OKCancel)
== MessageBoxResult.OK)
{
foreach (Dvd curr in thisapp.ShoppingCart)
{
if (curr.Equals(listBoxCart.SelectedItem))
{
listBoxCart.Items.Remove(curr);
listBoxCart.SelectedIndex = -1;
total -= Convert.ToDecimal(curr.price);
NavigationService.Navigate(new Uri("/ShoppingCart.xaml", UriKind.RelativeOrAbsolute));
}
}
txtBoxTotal.Text = total.ToString();
listBoxCart.ItemsSource = thisapp.ShoppingCart;
}
else
{
NavigationService.Navigate(new Uri("/ShoppingCart.xaml", UriKind.RelativeOrAbsolute));
}
}
【问题讨论】:
-
错误信息是什么?
-
InvalidOperationException 未处理
-
抱歉,只读集合不支持操作。
-
您不能从列表框中删除项目。您需要从提供的项目集合中删除项目。
-
@Fabrice 感谢您的快速回复,我完全采取了错误的方法,我只能添加/删除集合而不是列表框,非常感谢
标签: windows-phone-7 listboxitems