-
- realesmedia
- Posts: 85
- Joined:
[C++] Manual registering event in v1.3
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:
Can you give me solution for C++?
I can't understand how can I manual register event for next control:
Code: Select all
<CheckBox Name="CheckBox1" Checked="CheckBox1_Checked"/>
Last edited by realesmedia on 30 Dec 2016, 15:38, edited 3 times in total.
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: Manual registering event in v1.3
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:
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:
In the final version we want to provide a tool that will generate that code automatically for you.
In 1.3 beta3 you still have to do it manually by getting a reference to the named control:
Code: Select all
void OnPostInit()
{
CheckBox* cb = FindName<CheckBox>("CheckBox1");
cb->Checked() += MakeDelegate(this, &MyUserControl::CheckBox1_Checked);
//...
}
Code: Select all
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);
}
}
-
- realesmedia
- Posts: 85
- Joined:
Re: Manual registering event in v1.3
Thanks for your reply. Can you provide me header of handler function?
Produce error:
Code: Select all
void CheckBox1_Checked(Core::BaseComponent*, const EventArgs&){/*...*/}
Code: Select all
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>'
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: Manual registering event in v1.3
The signature of the event handler should be:
Code: Select all
#include <NoesisGUI.h>
//...
void CheckBox1_Checked(Noesis::BaseComponent* sender, const Noesis::RoutedEventArgs& args)
{
//...
}
Re: Manual registering event in v1.3
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.Code: Select allError 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>'
Thanks for the feedback!
Re: [C++] Manual registering event in v1.3
Just for the record, there is a new tutorial about events in the latest 1.3B4 version.
Who is online
Users browsing this forum: Google [Bot] and 0 guests