Events in WPF

  • Thread starter Thread starter Matt Armshaw
  • Start date Start date
M

Matt Armshaw

Guest
I would like to use the MouseDown event on a Canvas element. I know that the following code works:

mapBox.mapBoxC.MouseDown += new MouseButtonEventHandler(showMapBox);

when the method showMapBox includes the object sender and MouseButtonEventArgs e arguments. However, I need to pass an additional argument which will not be supported by the MouseButtonEventHandler delegate. I would like the MouseDown event to call a function with the following signature:

public void showMapBox(object sender, MouseButtonEventArgs e, Map_Box newMap)

I tried creating a custom delegate:

public delegate void MapBoxDB(Map_Box mapBox);

mapBox.mapBoxC.MouseDown += MapBoxDB(showMapBox)

where the showMapBox signature was:

public void showMapBox(Map_Box newMap)

but the compiler says it "cannot implicitly convert to System.Windows.Input.MouseButtonEventHandler".

Even if the above worked, how would I then pass the newMap object?

I have checked msdn resources, but have not found any articles detailing using the MouseDown event with a custom delegate.

Can someone point me in the right direction?

Continue reading...
 
Back
Top