using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace AutoCompleteListBuilder
{
public class GraphicsUtils
{
#region Double click
///
/// Holds the millis for the first click.
///
private long lastClickedTime = 0;
///
/// Delegate definition for the call back function.
///
///
///
public delegate void DoubleClickHandler(object sender, MouseButtonEventArgs e);
///
/// Holder for the call back function.
///
private DoubleClickHandler doubleClickCallBackFunction;
///
/// This will attach a double click to an object.
///
///
/// Due to Silverlight lack of double click event a custom implementation is needed.
/// this function and its adjacent handlers will attach a double click event to any object
/// deriving from UIElement.
///
/// the UIElement to attach the event to.
/// the function to call upon the double click event.
public void AttachDoubleClick(object doubleClickTarget, DoubleClickHandler function)
{
UIElement target = (UIElement)doubleClickTarget;
target.MouseLeftButtonUp += new MouseButtonEventHandler(target_MouseLeftButtonUp);
target.MouseLeftButtonDown += new MouseButtonEventHandler(target_MouseLeftButtonDown);
doubleClickCallBackFunction = function;
}
private void target_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
lastClickedTime = DateTime.Now.Ticks / 10000;
}
private void target_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
long currentMillis = DateTime.Now.Ticks / 10000;
if (currentMillis - lastClickedTime < 100 && currentMillis - lastClickedTime > 0)
{
doubleClickCallBackFunction(sender, e);
}
}
#endregion
}
}