There are many explanation in google, but I still struggling to implement mouse events.
MouseEnter=\"Canvas1_MouseEnter\"
in canva
Your canvas does not have the MouseEnter event. Use it like this
<Grid>
<Canvas HorizontalAlignment="Left" Height="158" Margin="191,85,0,0" VerticalAlignment="Top"
Width="221" Background="#FF575757" MouseEnter="Canvas_MouseEnter"/>
</Grid>
And then the Sub for the Event:
Private Sub Canvas_MouseEnter(sender As Object, e As MouseEventArgs)
MessageBox.Show("Hello?")
End Sub
UI elements in WPF do not receive mouse events (without mouse capture) outside their rendered area. A Panel (like your Canvas) does not render anything outside the area of its child elements unless you define a non-null value for its Background
property.
You may set a Background
for your Canvas like shown below, which makes it render the entire area defined by its ActualWidth and ActualHeight with a transparent brush:
<Canvas x:Name="Canvas1" Background="Transparent"
MouseEnter="Canvas1_MouseEnter" ... />