0

I made a visual basic User Control on WPF where some events are handled like MouseEnter or MouseLeftButtonDown inside its class.

Private Sub UCMenuButton_MouseEnter(sender As Object, e As MouseEventArgs) Handles Me.MouseEnter
    gridUCMenuButton.Background = New SolidColorBrush(System.Windows.Media.Color.FromRgb(53, 53, 53))
End Sub

Well, I would like to know how can I protect those Events to forbid the caller of this class or UC from being override on the parent. I want to be the threatment of those events exclusive and unique on the class and not on the user enviroment.

I tried with

RemoveHandler event, AddressOf eventhandler

or

IsHitTestVisible="False"

but those remove completely the event calling.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
  • 2
    When the user of your UserControl adds their own mouse event handler this does not "override" your handler. Your handler is still in place and works. – Clemens Mar 15 '18 at 10:00
  • That´s right. I posted wrongly my question. What I meant to ask is how can I disable the user of this UC to add events on it. I want to be my personal events unique. For example: I would like on MouseEnter to change the background color to grey and nothing more. Reflecting again I´m thinking maybe it´s a silly question and it can´t be done on this way. – Sergio Campos Mar 15 '18 at 10:21
  • Should be enough to set `e.Handled` to True. – Manfred Radlwimmer Mar 15 '18 at 10:33

1 Answers1

1

Thanks for the answers. I found the right one on this query related to the last comment @Manfred Radlwimmer posted.

Why e.Handled = true not working?

The issue can´t be solved due to it´s heritance. Apparently the user or parent event is handled before the class event. So if the user decide to give a functionality to the UC, this is executed before the class event handler. Then if I disable the functionality of the event on the class with e.handled = True, it will execute after and consecuently losing its purpose.

Hope it can help this explanation.