camimamedov
Topic Author
Posts: 6
Joined: 16 Feb 2024, 08:54

EventManager.RegisterClassHandler Unity crash

12 Mar 2024, 11:24

When i am trying to detect button clicks in one "OnButtonClick" method i get unity crash. I guess this handler is not unregister on disable. What can i use instead of it or how can i fix this problem? My noesis version is 3.2.2
            Noesis.EventManager.RegisterClassHandler(typeof(Button), Button.ClickEvent,
                new RoutedEventHandler(OnButtonClick));
 
User avatar
jsantos
Site Admin
Posts: 3997
Joined: 20 Jan 2012, 17:18
Contact:

Re: EventManager.RegisterClassHandler Unity crash

12 Mar 2024, 12:30

I think this is related to #2359. Is this happening on domain reload?
 
camimamedov
Topic Author
Posts: 6
Joined: 16 Feb 2024, 08:54

Re: EventManager.RegisterClassHandler Unity crash

12 Mar 2024, 12:36

I think this is related to #2359. Is this happening on domain reload?
Yes . But your reference post hasn't got any solution for Button clicks.
 
camimamedov
Topic Author
Posts: 6
Joined: 16 Feb 2024, 08:54

Re: EventManager.RegisterClassHandler Unity crash

15 Mar 2024, 08:04

Any help?
 
User avatar
sfernandez
Site Admin
Posts: 3064
Joined: 22 Dec 2011, 19:20

Re: EventManager.RegisterClassHandler Unity crash

27 Mar 2024, 12:00

Hi,

Do you really need to use EventManager.RegisterClassHandler, which is mostly intended to create custom controls?
Or will be enough to just hook to the Click event of your button in code behind:
<Grid x:Name="root">
  ...
  <Button x:Name="btn" Content="LOGIN"/>
</Grid>
Button btn = (Button)root.FindName("btn");
btn.Click += OnButtonClick;
Or even better, use a MVVM approach along with Commands to drive your app/game logic:
public class ViewModel
{
  public DelegateCommand LoginCommand { get; }
  ...
}
<Button Content="LOGIN" Command="{Binding LoginCommand}"/>
Please let me know if you need further assistance with any of this approaches.

Who is online

Users browsing this forum: No registered users and 3 guests