WPF - Best way to remove an item from the ItemsSource

前端 未结 4 544
日久生厌
日久生厌 2020-12-17 02:22

I\'m writing a custom ItemsControl (a tabbed document container), where each item (tab) can remove itself from the UI when the user closes it. However, I can\'t

4条回答
  •  别那么骄傲
    2020-12-17 02:31

    Design practice dictates that you should really know what your ItemsSource is and be able to remove it from there directly. The binding then automatically updates the view of course.

    However, if you are absolutely intent on some sort of generic functionality for removal, casting your ItemsSource to ICollection or ICollection and then calling Remove sounds like a better/more reliable way to go than using the dynamic features of .NET.

提交回复
热议问题