Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 477327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:34:47+00:00 2026-05-13T00:34:47+00:00

I need to be able to handle the double click and single click event

  • 0

I need to be able to handle the double click and single click event on the WPF StackPanel. But there is no such thing as the StackPanel’s DoubleClick Event.
I want to do 2 different operations in these 2 EventHandlers.

Any idea how to do that?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:34:48+00:00Added an answer on May 13, 2026 at 12:34 am

    The best way is to write your own mouse button handler with a timeout – if the event is fired again within the timeout period, then fire your doubleclick message, otherwise call the single click handler. Here’s some sample code (Edit: originally found here):

    /// <summary>
    /// For double clicks
    /// </summary>
    public class MouseClickManager {
        private event MouseButtonEventHandler _click;
        private event MouseButtonEventHandler _doubleClick;
    
        public event MouseButtonEventHandler Click {
            add { _click += value; }
            remove { _click -= value; }
        }
    
        public event MouseButtonEventHandler DoubleClick {
            add { _doubleClick += value; }
            remove { _doubleClick -= value; }
        }
    
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="MouseClickManager"/> is clicked.
        /// </summary>
        /// <value><c>true</c> if clicked; otherwise, <c>false</c>.</value>
        private bool Clicked { get; set; }
    
        /// <summary>
        /// Gets or sets the timeout.
        /// </summary>
        /// <value>The timeout.</value>
        public int DoubleClickTimeout { get; set; }
    
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseClickManager"/> class.
        /// </summary>
        /// <param name="control">The control.</param>
        public MouseClickManager(int doubleClickTimeout) {
            this.Clicked = false;
            this.DoubleClickTimeout = doubleClickTimeout;
        }
    
        /// <summary>
        /// Handles the click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        public void HandleClick(object sender, MouseButtonEventArgs e) {
            lock (this) {
                if (this.Clicked) {
                    this.Clicked = false;
                    OnDoubleClick(sender, e);
                }
                else {
                    this.Clicked = true;
                    ParameterizedThreadStart threadStart = new ParameterizedThreadStart(ResetThread);
                    Thread thread = new Thread(threadStart);
                    thread.Start(e);
                }
            }
        }
    
        /// <summary>
        /// Resets the thread.
        /// </summary>
        /// <param name="state">The state.</param>
        private void ResetThread(object state) {
            Thread.Sleep(this.DoubleClickTimeout);
    
            lock (this) {
                if (this.Clicked) {
                    this.Clicked = false;
                    OnClick(this, (MouseButtonEventArgs)state);
                }
            }
        }
    
        /// <summary>
        /// Called when [click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void OnClick(object sender, MouseButtonEventArgs e) {
            if (_click != null) {
                if (sender is Control) {
                    (sender as Control).Dispatcher.BeginInvoke(_click, sender, e);
                }
            }
        }
    
        /// <summary>
        /// Called when [double click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void OnDoubleClick(object sender, MouseButtonEventArgs e) {
            if (_doubleClick != null) {
                _doubleClick(sender, e);
            }
        }
    }
    

    Then, in the control you want to receive the events:

    MouseClickManager fMouseManager = new MouseClickManager(200);
    fMouseManager.Click += new MouseButtonEventHandler(YourControl_Click); 
    fMouseManager.DoubleClick += new MouseButtonEventHandler(YourControl_DoubleClick);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.