microsoft / cppwinrt

C++/WinRT
MIT License
1.64k stars 238 forks source link

IObservableVector in Derived class Size() is always 0 #1282

Closed jamespack closed 1 year ago

jamespack commented 1 year ago

Version

Latest available with vs 2022

Summary

I’m either doing something wrong(certainly possible) or there is a bug in the IObservableVector. I wrote a ViewModelBase class that handles property changed events as well as some other common properties one of which is an IObservableVector. The vector is used to bind to a Xaml navigation view for the menu items source. At startup I fill the collection and everything works as expected. I have a click handler in the application that is handled in a derived ViewModel that tries to loop over the collection to find a particular item. The problem is the property is a valid object but it seems to be empty. Size is reported as 0 and when I try to get an item I know is there there is an exception. I’ve tried making the viewmodelbase class both a runtime class and a regular old c++ struct. Same behavior in both cases. I’ve tried casting the derived to a base as well as many other things. Am I missing something? If this is not the right repo, happy to open an issue in the right place.

Reproducible example

I can link a GitHub repo is that’s helpful.

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

jamespack commented 1 year ago

Actually, nvm. Trying to put together a minimal repro example, I think I see what Im doing. They are not the same object. So that makes sense. doh :|