Page 1 of 1

Question about RaiseEvent(Args) and sample UserControl

Posted: 05 Mar 2018, 02:46
by UE4
In UserControl sample, I find the RaiseEvent(Args) is used to send event to MainWIndow, I want to know, if I have more than one event to send, how can I do it

MyControl.Xaml
<UserControl>
 	<TouchButton TouchDown="EventA" TouchUp="EventB"/>
</UserControl>
class
{
virtual bool ConnectEvent() override;
HandleEventA()
{
	RaiseEvent()// A
}
HandleEventB()
{
	RaiseEvent() //B
}

static const RoutedEvent* EventA;
static const RoutedEvent* EventB;
}
MainWindow.Xaml
<MainWindow> 
	<MyControl EventA="HandleEventA" EventB="HandleEventB"/>
</MainWindow>
class
{
virtual bool ConnectEvent() override;
HandleEventA();
HandleEventB();
}

Re: Question about RaiseEVent(Args) and sample UserControl

Posted: 05 Mar 2018, 07:48
by UE4
In UserControl, it is defined a raw Event:
//your sample
RoutedEvent_<Noesis::RoutedPropertyChangedEventHandler<int>::Handler> ValueChanged()
{
	return RoutedEvent_<RoutedPropertyChangedEventHandler<int>::Handler>(this, ValueChangedEvent);
}
And I defined a custom event:

Noesis::UIElement::RoutedEvent_<Noesis::TouchEventHandler> GameGUI::TouchButton::TouchButtonDown()
{
	//right way?
	return RoutedEvent_<TouchEventHandler>(this, TouchButtonDownEvent);
}



Re: Question about RaiseEVent(Args) and sample UserControl

Posted: 06 Mar 2018, 17:10
by hcpizzi
Hi,

As you figured out, if you want to create multiple custom events, you need multiple
static const Noesis::RoutedEvent*
members in your class. This RoutedEvent is passed as part of the RoutedEventArgs when you call RaiseEvent.

As for the type of the event arguments, it depends. The code you've added is valid, but the TouchEventArgs contain information, such as a position and the id of the finger it refers to, that may not be required in your case. You can use RoutedEventArgs (and RoutedEventHandler) if you have no other information to send other than that the event happened. But feel free to use TouchEventArgs if that's what you need.

Re: Question about RaiseEVent(Args) and sample UserControl

Posted: 07 Mar 2018, 07:48
by UE4
Hi,

As you figured out, if you want to create multiple custom events, you need multiple
static const Noesis::RoutedEvent*
members in your class. This RoutedEvent is passed as part of the RoutedEventArgs when you call RaiseEvent.

As for the type of the event arguments, it depends. The code you've added is valid, but the TouchEventArgs contain information, such as a position and the id of the finger it refers to, that may not be required in your case. You can use RoutedEventArgs (and RoutedEventHandler) if you have no other information to send other than that the event happened. But feel free to use TouchEventArgs if that's what you need.
thanks, got it.