Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i cant understand why custom canvas is not generating mouse events.

i have inherited class from Canvas. and added in XAML . Now iam unable to generate mouse events for the canvas .
plz help me how to generate mouse events for canvas now.

Xaml Code
VB
 xmlns:local="clr-namespace:Editor1"

<local:Mycanvas
      x:Name="Mycanvas"
      Background="AliceBlue"
      Grid.Column="1"
      Grid.RowSpan="2"
      Margin="-1.72235559148248E-09,30.8125,8,53.8125"
      Width="auto"
      Height="auto"
      MouseLeftButtonDown="Mycanvas_MouseLeftButtonDown"
      MouseMove="Mycanvas_MouseMove"
      MouseLeftButtonUp="Mycanvas_MouseLeftButtonUp">
        </local:Mycanvas>



canvas class
XML
public class Mycanvas:Canvas
    {
      // declarations

      public Mycanvas()
        {
          // do something
        }
}


tried with diiferent backgrounds but still not working?
where iam going wrong?


Thanks
Posted
Updated 17-Nov-11 19:20pm
v3
Comments
Mark Salsbery 18-Nov-11 3:58am    
Can you see the canvas when you run it? Why are width and Height set to "auto"? You do have the event handler methods in your class yes?
KiranBabu M 18-Nov-11 8:18am    
yes
event handlers are in Xaml.
when i run i cant see the canvas color

1 solution

In general WPF Handles hit testing with the help of brushes, seems you have a transparent background, I suspect it could be a potential cause, can you check if changing the background helps or not?
 
Share this answer
 
Comments
KiranBabu M 18-Nov-11 1:18am    
ya i have tried changing different backgrounds but still it is not working.
VallarasuS 18-Nov-11 1:25am    
in that case you have to check with the parent hierarchy, may be a parent control (grid or something) could consume the mouse events. try placing the canvas on a different window / content control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900