none
Double Click on TextBlock

    Question

  • Hi

    In my DataGrid I have TextBlock Column where I am showing it with underline and MouseLeftButtonUp Event Handler. I have remove this event at some condition So I have written the below code.

      txtBlock.TextDecorations = null;
                    txtBlock.Foreground = new SolidColorBrush(Colors.Black);
                    txtBlock.Cursor = Cursors.Arrow;
                    //Remove the event
                    txtBlock.MouseLeftButtonUp -= new MouseButtonEventHandler(TextBlock_MouseLeftButtonUp);
                }
                else
                {
                    //Explicitly add it to avoid errors while scrolling
                    txtBlock.TextDecorations = TextDecorations.Underline;
                    txtBlock.Foreground = new SolidColorBrush(Colors.Blue);
                    txtBlock.Cursor = Cursors.Hand;
                    txtBlock.MouseLeftButtonUp += new MouseButtonEventHandler(TextBlock_MouseLeftButtonUp);

     Here it is removing the Event Handler but there is a problem. When I click the link for the second time ( After many seconds) it is going to the click event handler. If click some other link and click back the previous link then it is not going to the event handler.

    Is it a bug in Silverlight?

    Thanks

    Anandraj.A.

    Tuesday, December 02, 2008 3:34 AM

Answers

  •  

    Hello,

    Do you want to impelment double click event on TextBlock?

    If you mean this, i write the code below:

    public long LastTicks = 0;

            private void TxtBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                if ((DateTime.Now.Ticks - LastTicks) < 3000000)
                {
                    // double click event, you can write the logic here

                }
                LastTicks = DateTime.Now.Ticks;
            }

     Hope this helps.

    Tuesday, December 02, 2008 5:51 AM

All replies

  •  Please define what you want to accomplish instead

    Tuesday, December 02, 2008 3:41 AM
  •  

    Hello,

    Do you want to impelment double click event on TextBlock?

    If you mean this, i write the code below:

    public long LastTicks = 0;

            private void TxtBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                if ((DateTime.Now.Ticks - LastTicks) < 3000000)
                {
                    // double click event, you can write the logic here

                }
                LastTicks = DateTime.Now.Ticks;
            }

     Hope this helps.

    Tuesday, December 02, 2008 5:51 AM
  • This is probably the simplest and fastest method.  It uses a DateTime instead of Timer

    http://csharping.com/silverlight/a-simple-double-click-handler-for-silverlight-wpf/

    Monday, April 11, 2011 9:42 AM