DominikRuta
Topic Author
Posts: 2
Joined: 19 Dec 2023, 15:03

Handling UIElement events in UE5

19 Dec 2023, 15:39

Hello, I have a simple question. Is there a way how to listen on UIElement events and handle them in UE5 c++ class while still getting event arguments like this?
	void UMyUnrealView::OnMouseWheel(BaseComponent* component, const Noesis::MouseWheelEventArgs& e)
	{
		// Do some stuff
		return;
	}
Registering the callback in XAML would look something like this:
	<Canvas MouseWheel="OnMouseWheel">
		...
	</Canvas>
I know how to listen on them like this using Behaviors, but in some cases, I need context of that view object.

Thank you
 
User avatar
hcpizzi
Site Admin
Posts: 321
Joined: 09 Feb 2012, 12:40

Re: Handling UIElement events in UE5

19 Dec 2023, 18:12

If I understand it correctly, you want to be able to receive the event arguments in a handler function in your ViewModel, which is an UObject derived class. Am I right?

In that case, that is not possible at the moment. If all you need is to know the source of the event, that could be done using behaviors.
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Handling UIElement events in UE5

22 Dec 2023, 10:20

It's already been reported the possibility to receive event arguments as the command parameter in the InvokeCommandAction, but it's still not implemented: #2723

If you only need to receive the element that sent the event (although it is rare that in a ViewModel you need to know about a specific UI element of the view), you can pass it as the command parameter:
<Canvas x:Name="canvas" Background="Transparent">
  <b:Interaction.Triggers>
    <b:EventTrigger EventName="MouseWheel">
      <b:InvokeCommandAction Command="{Binding SomeCommand}" CommandParameter="{Binding ElementName=canvas}"/>
    </b:EventTrigger EventName="MouseWheel">
  </b:Interaction.Triggers>
</Canvas>

Who is online

Users browsing this forum: Bing [Bot] and 7 guests