Unity: Some button mouse events fire, others do not?
In Unity, some button events appear to fire(click, doubleclick, enter), but others do not(mousedown, mouseup).
Any reason why?
Any reason why?
Code: Select all
void Start()
{
FrameworkElement root = noesis_view.Content;
Button btn = (Button)root.FindName("Button_Main");
//does not fire
btn.MouseLeftButtonUp += Btn_MouseLeftButtonUp;
btn.MouseUp += Btn_MouseUp;
btn.MouseDown += Btn_MouseDown;
//does fire
btn.Click += Btn_Click;
btn.MouseEnter += Btn_MouseEnter;
btn.MouseDoubleClick += Btn_MouseDoubleClick;
}
private void Btn_MouseDown(object sender, MouseButtonEventArgs args)
{
Debug.Log("Btn_MouseDown!!!!");
}
private void Btn_Click(object sender, RoutedEventArgs args)
{
Debug.Log("Btn_Click!!!!");
}
-
sfernandez
Site Admin
- Posts: 2995
- Joined:
Re: Unity: Some button mouse events fire, others do not?
It is because Button class handles some of them to implement the Click logic.
A Button with ClickMode=Release will notify you about the following events:
Once MouseLeftButtonDown is routed through the Button it marks e.Handled as true and you won't be able receive that event or MouseDown event. The same happens with MouseUp/MouseLeftButtonUp events.
A Button with ClickMode=Release will notify you about the following events:
Code: Select all
PreviewMouseLeftButtonDown
PreviewMouseDown
PreviewMouseLeftButtonUp
PreviewMouseUp
Click
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 25 guests