Mouse Move :


♣    This event will fire when user will move the mouse with in the WPF window

Mouse Down :


♣    This event will fire when user will press the mouse button

Mouse Double Click :


♣    This event will fire when user will double click the mouse with in the WPF window

Step 1 :


♣    Using properties Window Generate the Mouse Move Event

Step 2 :   MainWindow.xaml.cs Code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DrawLineWithMouse
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        Point p1 = new Point();
        Point p2 = new Point();
        bool a1 = true;

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if (a1 == true)
            {
                p1 = e.GetPosition(g1);
                a1 = false;
            }
            p2 = e.GetPosition(g1);
            drawline();
        }
        public void drawline()
        {
            Line l1 = new Line();
            l1.X1 = p1.X;
            l1.Y1 = p1.Y;
            l1.X2 = p2.X;
            l1.Y2 = p2.Y;
            l1.Stroke = System.Windows.Media.Brushes.Red;
            l1.StrokeThickness = 5;
            g1.Children.Add(l1);
        }
    }
}

Output :


wpf344