Question about RaiseEvent(Args) and sample UserControl
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
MainWindow.Xaml
MyControl.Xaml
Code: Select all
<UserControl>
<TouchButton TouchDown="EventA" TouchUp="EventB"/>
</UserControl>
Code: Select all
class
{
virtual bool ConnectEvent() override;
HandleEventA()
{
RaiseEvent()// A
}
HandleEventB()
{
RaiseEvent() //B
}
static const RoutedEvent* EventA;
static const RoutedEvent* EventB;
}
Code: Select all
<MainWindow>
<MyControl EventA="HandleEventA" EventB="HandleEventB"/>
</MainWindow>
Code: Select all
class
{
virtual bool ConnectEvent() override;
HandleEventA();
HandleEventB();
}
Re: Question about RaiseEVent(Args) and sample UserControl
In UserControl, it is defined a raw Event:
Code: Select all
//your sample
RoutedEvent_<Noesis::RoutedPropertyChangedEventHandler<int>::Handler> ValueChanged()
{
return RoutedEvent_<RoutedPropertyChangedEventHandler<int>::Handler>(this, ValueChangedEvent);
}
Code: Select all
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
Hi,
As you figured out, if you want to create multiple custom events, you need multiple 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.
As you figured out, if you want to create multiple custom events, you need multiple
Code: Select all
static const Noesis::RoutedEvent*
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
thanks, got it.Hi,
As you figured out, if you want to create multiple custom events, you need multiplemembers in your class. This RoutedEvent is passed as part of the RoutedEventArgs when you call RaiseEvent.Code: Select allstatic const Noesis::RoutedEvent*
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.
Who is online
Users browsing this forum: No registered users and 68 guests