nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Implementing Attached Properties in C++

10 Aug 2017, 11:00

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 ?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Implementing Attached Properties in C++

10 Aug 2017, 17:07

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
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Re: Implementing Attached Properties in C++

11 Aug 2017, 09:12

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 ?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Implementing Attached Properties in C++

11 Aug 2017, 12:54

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.
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Re: Implementing Attached Properties in C++

11 Aug 2017, 13:53

Confirmed that works. Thanks !
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Implementing Attached Properties in C++

16 Aug 2017, 11:59

Nice, I will mark this as solved.

Who is online

Users browsing this forum: camimamedov, Semrush [Bot] and 41 guests