I make Drag & Drop based on this answer .

There is a CustomControl that inherits from ToggleButton . I bind methods to events in the constructor, but in this way events are not processed.

How to do?

 public class CustomControl: ToggleButton { public CustomControl() { this.MouseLeftButtonDown += OnMouseDown; this.MouseLeftButtonUp += OnMouseUp; } void OnMouseDown(object sender, MouseButtonEventArgs e) { //... } void OnMouseUp(object sender, MouseButtonEventArgs e) { //... } } 

    1 answer 1

     public class CustomControl : ToggleButton { protected override void OnMouseDown(MouseButtonEventArgs e) { base.OnMouseDown(e); } protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); } } 
    • one
      That works, thanks! Can you explain why we do this? - trydex
    • one
      @maxwell If we inherit from the control to expand or change its behavior, then it is more correct to override the necessary methods of the standard control through override and there already write the logic of your control. - Murad
    • Understood thanks! - trydex