UserControl Event Not Firing

RogerSchlueter-7899 1,301 Reputation points
2020-11-29T02:28:24.357+00:00

I am trying to create a small dot that the user can move around a map. I use a UserControl for the dot:

<UserControl
....

MouseDown="MeMouseDown"
MouseUp="MeMouseUp"
MouseMove="MeMouseMove"
<Ellipse
        Fill="{Binding Path=FillColor}"
        Height="{Binding Path=Diameter}"
        Width="{Binding Path=Diameter}" >
    </Ellipse>
</UserControl>

Considering just the MouseDown event, I have in code-behind:

Public Class Dot
    Inherits UserControl

    .....
    Public Event MyMouseDown As RoutedEventHandler
    .....
    Private Sub MeMouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        RaiseEvent MyMouseDown(sender, e)
    End Sub

The code that creates the dot is:

Private Sub DrawPoint(Colr As SolidColorBrush, Radius As Double)
        Dim ADot As New Dot With {.FillColor = Colr, .Diameter = 2 * Radius}
        ....
    End Sub

and finally, responding to the MouseDown event:

Private Sub MyMouseDown(sender As Object, e As MouseButtonEventArgs)
        Debug.WriteLine("MyMouseDown")
    End Sub

That Debug statement does not fire when I click on the dot and I don't know why.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,770 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,159 questions
{count} votes

Accepted answer
  1. RogerSchlueter-7899 1,301 Reputation points
    2020-12-11T22:50:36.12+00:00

    The MouseUp event is fired if the MouseDown event includes e.handled = True

    This resolves the issue for me. However, I have another issue involving this UserControl but I'll put that in a separate post.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Viorel 117.2K Reputation points
    2020-11-29T03:32:11.707+00:00

    Try moving MouseDown, or adding something like MouseDown="EllipseMouseDown" to <Ellipse>. Then you will be able to identify the clicks on ellipse and on User Control.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.