Page 1 of 1

Implementing Attached Properties in C++

Posted: 10 Aug 2017, 11:00
by nikobarli
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)
EventToCommand.PNG
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 ?

Re: Implementing Attached Properties in C++

Posted: 10 Aug 2017, 17:07
by sfernandez
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

Re: Implementing Attached Properties in C++

Posted: 11 Aug 2017, 09:12
by nikobarli
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:
    <Grid
        Background="AntiqueWhite"
        local:EventToCommand.Command="{Binding MouseDownCommand}"
        local:EventToCommand.Event="MouseDown">
        <TextBlock FontSize="40" VerticalAlignment="Center" HorizontalAlignment="Center">
            Click me !
        </TextBlock>
    </Grid>
then I need to make EventToCommand class inherits from BaseComponent and call NS_REGISTER_COMPONENT(EventToCommand); during initialization.
Is that correct ?

Re: Implementing Attached Properties in C++

Posted: 11 Aug 2017, 12:54
by sfernandez
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++

Posted: 11 Aug 2017, 13:53
by nikobarli
Confirmed that works. Thanks !

Re: Implementing Attached Properties in C++

Posted: 16 Aug 2017, 11:59
by sfernandez
Nice, I will mark this as solved.