0

我在 WPF 中创建了一个 ListBox,其中ItemSource包含所有使 UI 刷新的类和事件。但是我的Remove方法有个问题:

Public Sub Remove(ItemIndex As Integer)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex)))
End Sub

但是当我执行此操作时,我收到一条消息,指出索引(在这种情况下ItemIndex)超出范围。但是在输出窗口中它说索引是'0'(否则它会从 中删除该项目MyList)。

4

1 回答 1

0

问题解决了!我更改了代码

Public Sub Remove(ItemIndex As Integer)
MyList.RemoveAt(ItemIndex)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex)))
End Sub

进入

Public Sub Remove(ItemIndex As Integer)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, MyList(ItemIndex), ItemIndex))
MyList.RemoveAt(ItemIndex)
End Sub

就这样。

于 2013-06-02T09:24:46.780 回答