I ran into a similar problem when subclassing ListView. In my case, the following approach partially helped: I stopped trying to set the ItemsSource of my ListView directly in the code behind, but instead I created a CollectionViewSource in XAML, for example:
<UserControl.Resources> <CollectionViewSource x:Name="myCollectionViewSource"/> </UserControl.Resources> ... ... <ListView ... ItemsSource="{Binding Source={StaticResource myCollectionViewSource}}" />
And in the code behind, I set
this.myCollectionViewSource.Source = new List<Object> { new Object() };
However, this only puts off the problem. At least in my case. In my real-life example, I use the ObservableVector as a data source. And as soon as any change to the ObservableVector collection is done (e.g. Clear), I also crash (0x8000FFFF). As soon as I use the original ListView (and not my subclass version), everything works fine again - exactly the same as in your case. Therefore, my answer cannot be understood as a solution to the problem, but perhaps this is a hint that is worth a try. In my case, the original assignment works fine, problems occur first after the observed collection tries to update. I experimented with an ObservableCollection (should work in CP, this is not in DP), but there I ran into other problems. It would be interesting to hear if you were able to advance along this path ...
source share