ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Converts a complex multitouch, pressure sensitive silverlight stylus object to a simple MouseInfo object.


using System;
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;

public class MouseInfo
    public double X { get; set; }
    public double Y { get; set; }
    public bool MouseDown { get; set; }
public static class MouseMethods
    public static MouseInfo ToMouseInfo(this System.Windows.Input.MouseEventArgs e, object sender)
        MouseInfo mi = new MouseInfo();
        Point p = e.GetPosition(sender as UIElement);
        mi.MouseDown = e.GetStylusPoints(sender as UIElement)[0].PressureFactor > 0;
        mi.X = p.X;
        mi.Y = p.Y;
        return mi;


MouseInfo mi = e.ToMouseInfo(sender);
if (mi.MouseDown)
    mediatest.SetValue<double>(Canvas.LeftProperty, mi.X);
    mediatest.SetValue<double>(Canvas.TopProperty, mi.Y);

Author: Loek van den Ouweland

Submitted on: 18 dec. 2007

Language: C#

Type: System.Windows.Input.MouseEventArgs

Views: 4426