DependencyProperty with string value
What is the proper way to implement a DependencyProperty that represents a string value? I have a simple UserControl object that is basically just some text blocks whose text I want to expose with Dependency Properties so I may set it programmatically. I have these properties as NsStrings right now but I get compilation errors when using NsProp.
Should the values be cast to NsStrings, or should it be another type? Do the function pointers provided to NsProp need to be of a certain signature? Right now for my setter I am passing in a NsString which I don't really want to do (I'd rather pass in a const NsString& or an NsString*).
I'm curious what the best way to do this is - the examples only seem to cover numeric types.
Should the values be cast to NsStrings, or should it be another type? Do the function pointers provided to NsProp need to be of a certain signature? Right now for my setter I am passing in a NsString which I don't really want to do (I'd rather pass in a const NsString& or an NsString*).
I'm curious what the best way to do this is - the examples only seem to cover numeric types.
Re: DependencyProperty with string value
The functions passed to NsProp must use const NsString&:
The property is registered using the NsString type:
Code: Select all
const NsString& MyClass::GetText() const
{
return GetValue<NsString>(TextProperty);
}
void MyClass::SetText(const NsString& text)
{
SetValue<NsString>(TextProperty, text);
}
...
NsProp("Text", &MyClass::GetText, &MyClass::SetText);
Code: Select all
data->RegisterProperty<NsString>(TextProperty, "Text",
FrameworkPropertyMetadata::Create(NsString(), FrameworkOptions_None));
Re: DependencyProperty with string value
Hi,
I have a question which could be related this.
I also have some UserControl contaning some strings.
Right now i am using string not NsString, and it's working. Is it correct to use string for dependcy properties in Unity?
Thanks in advance.
I have a question which could be related this.
I also have some UserControl contaning some strings.
Right now i am using string not NsString, and it's working. Is it correct to use string for dependcy properties in Unity?
Thanks in advance.
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: DependencyProperty with string value
Yes, mono strings are automatically converted to native NsString, so that is the correct way to define a string property in Unity.Hi,
I have a question which could be related this.
I also have some UserControl contaning some strings.
Right now i am using string not NsString, and it's working. Is it correct to use string for dependcy properties in Unity?
Thanks in advance.
Re: DependencyProperty with string value
ok thanks
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests