Page 1 of 1

EventManager.RegisterClassHandler Unity crash

Posted: 12 Mar 2024, 11:24
by camimamedov
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));

Re: EventManager.RegisterClassHandler Unity crash

Posted: 12 Mar 2024, 12:30
by jsantos
I think this is related to #2359. Is this happening on domain reload?

Re: EventManager.RegisterClassHandler Unity crash

Posted: 12 Mar 2024, 12:36
by camimamedov
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.

Re: EventManager.RegisterClassHandler Unity crash

Posted: 15 Mar 2024, 08:04
by camimamedov
Any help?

Re: EventManager.RegisterClassHandler Unity crash

Posted: 27 Mar 2024, 12:00
by sfernandez
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.