realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

[C++] Manual registering event in v1.3

28 Dec 2016, 13:15

v1.2 allows to register events with NsFunc macro, but it's no longer supported in reflection macros.
I can't understand how can I manual register event for next control:
<CheckBox Name="CheckBox1" Checked="CheckBox1_Checked"/>
Can you give me solution for C++?
Last edited by realesmedia on 30 Dec 2016, 15:38, edited 3 times in total.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Manual registering event in v1.3

28 Dec 2016, 15:14

In v1.3 we are in the process of generating code for automatic event registering, the same way WPF does when you build the project and it generates a "????.g.cs" file with a partial implementation of your code behind root class.

In 1.3 beta3 you still have to do it manually by getting a reference to the named control:
void OnPostInit()
{
  CheckBox* cb = FindName<CheckBox>("CheckBox1");
  cb->Checked() += MakeDelegate(this, &MyUserControl::CheckBox1_Checked);
  //...
}
For the upcoming 1.3 beta4 we are preparing now, we will provide an overrideable funtion in the FrameworkElement that will alllow you to register events even on unnamed controls, in a way more similar how WPF does:
void Connect(BaseComponent* source, const NsChar* eventName, const NsChar* handlerName) override
{
  if (String::Compare(eventName, "Checked") == 0 && String::Compare(handlerName, "CheckBox1_Checked") == 0)
  {
    CheckBox* element = NsStaticCast<CheckBox*>(source);
    element->Checked() += MakeDelegate(this, &MyUserControl::CheckBox1_Checked);
  }
}
In the final version we want to provide a tool that will generate that code automatically for you.
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Manual registering event in v1.3

28 Dec 2016, 15:31

Thanks for your reply. Can you provide me header of handler function?
void CheckBox1_Checked(Core::BaseComponent*, const EventArgs&){/*...*/}
Produce error:
Error C2440	'<function-style-cast>': cannot convert from 'Noesis::Core::Delegate<void (Noesis::Core::BaseComponent *,const Noesis::Gui::RoutedEventArgs &)>::{ctor}::ERROR_INSUFFICIENT_SIZE' to 'Noesis::Core::CompileTimeChecker<false>'	
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Manual registering event in v1.3

28 Dec 2016, 16:22

The signature of the event handler should be:
#include <NoesisGUI.h>

//...

void CheckBox1_Checked(Noesis::BaseComponent* sender, const Noesis::RoutedEventArgs& args)
{
 //...
} 
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Manual registering event in v1.3

29 Dec 2016, 06:59

Thanks. Works for me now.
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: Manual registering event in v1.3

29 Dec 2016, 16:21

Error C2440	'<function-style-cast>': cannot convert from 'Noesis::Core::Delegate<void (Noesis::Core::BaseComponent *,const Noesis::Gui::RoutedEventArgs &)>::{ctor}::ERROR_INSUFFICIENT_SIZE' to 'Noesis::Core::CompileTimeChecker<false>'	
This kind of alien errors when using delegates will also be fixed in the next beta. I am working right now in a tutorial explaining everything about manually registering events with Noesis.

Thanks for the feedback!
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: [C++] Manual registering event in v1.3

03 Jan 2017, 02:15

Just for the record, there is a new tutorial about events in the latest 1.3B4 version.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Dmirty, Semrush [Bot] and 15 guests