Implementing Attached Properties in C++
Hi, I am trying to translate the following WPF attached properties using Noesis C++ SDK. (The original code is here: http://www.mobilemotion.eu/?p=1822)
But I am not sure the correct way to do it.
# Sorry to attached the code by image. The forum refused to work when I submitted the data using 'code' or 'quote' tags.
For example, when registering the reflection for Command property, should I use data->RegisterProperty<ICommand>, or data->RegisterProperty<Ptr<ICommand>> or maybe data->RegisterProperty<Ptr<BaseCommand>> ?
Similarly, when registering the reflection for Event property, should I use data->RegisterProperty<NsString> ? Compiler complains with ambiguous == operator when I did this.
Could you please post the correct C++ code for this ?
But I am not sure the correct way to do it.
# Sorry to attached the code by image. The forum refused to work when I submitted the data using 'code' or 'quote' tags.
For example, when registering the reflection for Command property, should I use data->RegisterProperty<ICommand>, or data->RegisterProperty<Ptr<ICommand>> or maybe data->RegisterProperty<Ptr<BaseCommand>> ?
Similarly, when registering the reflection for Event property, should I use data->RegisterProperty<NsString> ? Compiler complains with ambiguous == operator when I did this.
Could you please post the correct C++ code for this ?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Implementing Attached Properties in C++
Please find the code in the following link, as I also got errors when writing the code directly in the post, we will investigate what is happening.
https://gist.github.com/s-fernandez-v/5 ... ce428808bd
https://gist.github.com/s-fernandez-v/5 ... ce428808bd
Re: Implementing Attached Properties in C++
Great, thank you. I can learn many things from the code. Especially on how to use the reflection related APIs.
One additional question though. If I want to use the EventToCommand class from XAML like this:
then I need to make EventToCommand class inherits from BaseComponent and call NS_REGISTER_COMPONENT(EventToCommand); during initialization.
Is that correct ?
One additional question though. If I want to use the EventToCommand class from XAML like this:
Code: Select all
<Grid
Background="AntiqueWhite"
local:EventToCommand.Command="{Binding MouseDownCommand}"
local:EventToCommand.Event="MouseDown">
<TextBlock FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center">
Click me !
</TextBlock>
</Grid>
Is that correct ?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Implementing Attached Properties in C++
Not necessarily, the only requirement is that EventToCommand type is registered in Noesis reflection registry. We should probably add a NS_REGISTER_TYPE macro for that, similar to the one used for components, but for now you can simply trigger the type registration by calling TypeOf<EventToCommand>() in your NsRegisterReflection function.
Re: Implementing Attached Properties in C++
Confirmed that works. Thanks !
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Implementing Attached Properties in C++
Nice, I will mark this as solved.
Who is online
Users browsing this forum: camimamedov, Semrush [Bot] and 41 guests