I think the PreviewMouseLeftButtonUp (Down) event is better suited for your needs. Then you need to process ClickCount to count the number of clicks, and then raise your own event, on which other controls will know that your control will be clicked. There are many more click processing methods. You should look at this article msdn and this
UPDATE to handle both Click and DoubleClick
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); _myCustomUserControl.MouseLeftButtonUp += new MouseButtonEventHandler(_myCustomUserControl_MouseLeftButtonUp); _myCustomUserControl.MouseDoubleClick += new MouseButtonEventHandler(_myCustomUserControl_MouseDoubleClick); } bool _doubleClicked; void _myCustomUserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) { _textBlock.Text = "Mouse left button clicked twice"; _doubleClicked = true; e.Handled = true; } void _myCustomUserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_doubleClicked) { _doubleClicked = false; return; } _textBlock.Text = "Mouse left button clicked once"; e.Handled = true; } }
To test this example, name your control as _myCustomUserControl and add a TextBlock named _textBlock in your MainWindow.xaml
Eugene cheverda
source share