C++ DependencyProperty types
Shouldn't my string be an NsString (I get an error if I use this) and i'm getting an error with ImageSource. What's the correct setup?
https://pastebin.com/0sV17D68
https://pastebin.com/0sV17D68
Re: C++ DependencyProperty types
For strings you must use the NsString class when registering the DependencyProperty.
Code: Select all
Data->RegisterProperty<NsString>(LabelProperty, "Label", FrameworkPropertyMetadata::Create(FrameworkOptions_None));
Code: Select all
const char* AttributeControl::GetLabel() const
{
return Noesis::ContentControl::GetValue<NsString>(LabelProperty).c_str();
}
void AttributeControl::SetLabel(const char* label)
{
Noesis::ContentControl::SetValue<NsString>(LabelProperty, label);
}
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: C++ DependencyProperty types
And for the ImageSource you have to specify it like this:
We have to improve this code to hide NsString and Ptr inside DependencyObject implementation. So users deal only with basic types like const char* and ImageSource* when doing RegisterProperty and GetValue/SetValue.
Code: Select all
Data->RegisterProperty<Ptr<ImageSource>>(IconProperty, "Icon", FrameworkPropertyMetadata::Create(Ptr<ImageSource>(), FrameworkOptions_None));
Code: Select all
Noesis::ImageSource* AttributeControl::GetIcon() const
{
return Noesis::DependencyObject::GetValue<Ptr<ImageSource>>(IconProperty);
}
void AttributeControl::SetIcon(Noesis::ImageSource* imageSource)
{
Noesis::DependencyObject::SetValue<Ptr<ImageSource>>(IconProperty, imageSource);
}
Re: C++ DependencyProperty types
I made some helpers that could be integrated, although it's not the best for char* (non-const):
Code: Select all
#pragma once
#define NS_DECLARE_PROPERTY(PropertyType, PropertyName) \
static const Noesis::DependencyProperty* PropertyName##Property; \
const PropertyType Get##PropertyName() const; \
void Set##PropertyName(PropertyType PropertyName);
#define NS_DEFINE_PROPERTY(ClassName, PropertyType, PropertyName) \
const DependencyProperty* ClassName::PropertyName##Property; \
const PropertyType ClassName::Get##PropertyName() const \
{ \
return Noesis::Control::GetValue<PropertyType>(PropertyName##Property); \
} \
void ClassName::Set##PropertyName(PropertyType PropertyName) \
{ \
Noesis::Control::SetValue<PropertyType>(PropertyName##Property, PropertyName); \
}
Re: C++ DependencyProperty types
Thanks for the macros. They neither work with Ptr<> properties. But it will work in the future when we change them to something like:
This is a breaking change, so won't happen soon. Honestly I am not sure about how to deal with strings, because I think that char* and NsString are different things.
Code: Select all
ImageSource* AttributeControl::GetIcon() const
{
return DependencyObject::GetValue<ImageSource*>(IconProperty);
}
void AttributeControl::SetIcon(ImageSource* imageSource)
{
DependencyObject::SetValue<ImageSource*>(IconProperty, imageSource);
}
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 89 guests