views:

167

answers:

2

I have a WPF Custom Control inherited from Button.

How do I programatically get the custom control to capture the Click Event (so that I can record the action and do some internal work) (basically I want to catch the event and set a certain property to a certain value) and make this part of the classes standard functionality.

From my understanding the custom control should be able to catch it's own even and do some work.

Help appreciated

A: 

try one of the overrides

   public class CustomButton : Button {

      protected override void OnPreviewMouseDown(MouseButtonEventArgs e) {
         base.OnPreviewMouseDown(e);
      }

      protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) {
         base.OnPreviewMouseLeftButtonDown(e);
      }
   }
Aran Mulholland
A: 

I have realised why Ihad a problem. I could not see the Click event This was because I was not explicit enought in my class declaration:

I put

public class StateButton : Button

obviously picked the wrong button .. as

public class StateButton : System.Windows.Controls.Button

works

Then I just override the event

Thanks

Adam
do you mean you did as i suggested in my answer? If so mark it as answered. Stack overflow works a lot better when people mark the questions as answered (if they are - and i think this one is), its one of the ways to payback the other users for taking time to answer your questions. when you mark someone as answering your question, they get status points.
Aran Mulholland
the reason this didnt work is probably because you added a reference to the windows forms button, have a look at your using statements.
Aran Mulholland