Page 1 of 1

PropertyMetadata - Property Changed Callback

Posted: 25 Aug 2021, 00:19
by jsteedVR
Hi,

I have a DependencyProperty in my custom control that I am trying to register.
static const DependencyProperty *SelectedItemsProperty;
NS_IMPLEMENT_INLINE_REFLECTION(MultiSelectTreeView, TreeView)
		{
			NsMeta<TypeId>("Vital.MultiSelectTreeView");

			DependencyData *data = NsMeta<DependencyData>(TypeOf<SelfClass>());

			data->RegisterProperty<Ptr<ObservableCollection<BaseComponent>>>(SelectedItemsProperty, "SelectedItems",
				PropertyMetadata::Create(&OnSelectedItemsChanged));
		}
I want to supply the PropertyMetadata with this callback for when the property changes:
void OnSelectedItemsChanged(BaseComponent *_sender, const DependencyPropertyChangedEventArgs &e);
But when I compile, Noesis throws this error:
NoesisSDK_2.2.0\Include\NsCore/TypeOfBase.inl(29,49): error C2825: 'T': must be a class or namespace when followed by '::'
NoesisSDK_2.2.0\Include\NsGui/PropertyMetadata.inl(18): message : see reference to class template instantiation 'Noesis::ValueStorageManagerImpl<T>' being compiled
I've tried calling a few different overloads of PropertyMetadata::Create, but cannot get it to work.
The property changed callback is the only important thing I need the metadata to have. Do I need to supply a ValueStorageManager?

Can someone share some examples of how this should look?
I'm using the Noesis 2.2 C++ SDK.

Thanks in advance :)

Re: PropertyMetadata - Property Changed Callback

Posted: 25 Aug 2021, 11:42
by sfernandez
Hi, the correct signature for the PropertyChangedCallback is:
void PropertyChangedCallback(DependencyObject* d, const DependencyPropertyChangedEventArgs& e);
Please let us know if you find any more problems.

Re: PropertyMetadata - Property Changed Callback

Posted: 25 Aug 2021, 19:13
by jsteedVR
Hi, the correct signature for the PropertyChangedCallback is:
void PropertyChangedCallback(DependencyObject* d, const DependencyPropertyChangedEventArgs& e);
Please let us know if you find any more problems.
I still get the same error(s) using that signature.

Re: PropertyMetadata - Property Changed Callback

Posted: 27 Aug 2021, 10:12
by sfernandez
Sorry for the late answer. The following code compiles fine with NoesisGUI 2.2 version:
class MultiSelectTreeView : public TreeView
{
public:
  static const DependencyProperty *SelectedItemsProperty;
private:
  static void OnSelectedItemsChanged(DependencyObject* d, const DependencyPropertyChangedEventArgs& e)
  {
  }
  
  NS_IMPLEMENT_INLINE_REFLECTION(MultiSelectTreeView, TreeView)
  {
    NsMeta<TypeId>("Vital.MultiSelectTreeView");

    DependencyData *data = NsMeta<DependencyData>(TypeOf<SelfClass>());
    data->RegisterProperty<Ptr<ObservableCollection<BaseComponent>>>(SelectedItemsProperty, "SelectedItems",
      PropertyMetadata::Create(PropertyChangedCallback(OnSelectedItemsChanged)));
  }
};

Re: PropertyMetadata - Property Changed Callback

Posted: 27 Aug 2021, 22:32
by jsteedVR
Ah, that works.
The part that was not obvious to me was that OnSelectedItemsChanged needed to be wrapped in a PropertyChangedCallback inside PropertyMetadata::Create parameter.

As always, thanks a ton for the help!

Re: PropertyMetadata - Property Changed Callback

Posted: 27 Aug 2021, 22:59
by jsantos
Thanks for the feedback. Also note that 2.2 is incredibly old, we recommend upgrading to 3.1

Re: PropertyMetadata - Property Changed Callback

Posted: 27 Aug 2021, 23:16
by jsteedVR
We are currently in the discovery phase of what work it will take to upgrade our codebase to 3.1 in the next month or two, but we are very excited for it.
Thanks again for all that you guys do!