Made a small test form. Clicking on <Canvas Name="BallsCentralStage" MouseDown="MouseDownHandler"> should generate a MouseDown event. On this event hung up the handler MouseDownHandler , which is in the class MainWindow (ie, in the main window). How, after all, when you click on the canvas to handle the event?

 <Window x:Class="PhysicsOfBalls.MainWindow"> <DockPanel Name="MainDockPanel" VerticalAlignment="Stretch"> <TabControl Name="MainTabControl"> <TabItem Header="Settings" Name="SettingsTab"></TabItem> <TabItem Header="Stage" Name="CanvasTab"> <Canvas Name="BallsCentralStage" MouseDown="MouseDownHandler" Width="654" /> </TabItem> </TabControl> </DockPanel> </Window> 
  • And what exactly is the problem? While you seem to be doing everything right. - VladD
  • The handler must draw the object to the canvas, but this does not happen. Put breakpoint on the handler - it is not caused. It works only if you hang the line MouseDown = "MouseDownHandler" on each parent tag, but this is not exactly what you need. - nullptr
  • @nullptr: oh, see, see the answer. - VladD

1 answer 1

Try to set the background, though transparent:

 <Canvas Name="BallsCentralStage" MouseDown="MouseDownHandler" Width="654" Background="Transparent" /> 

Many elements without a background are “transparent” for clicks and other mouse events.

  • Works! Thank! He killed a few hours for this error, and here it turns out everything is simple) - nullptr
  • @nullptr: Please! - VladD