Canvas PreviewMouseDown action and MouseDown action : Canvas « Windows Presentation Foundation « C# / C Sharp

Canvas PreviewMouseDown action and MouseDown action

Canvas PreviewMouseDown action and MouseDown action
<Window x:Class="WpfApplication1.Window1"
    Title="AddHandler" Height="300" Width="300">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">

          <ColumnDefinition />
          <ColumnDefinition />

        <Canvas PreviewMouseDown="PreviewMouseDownCanvas" MouseDown="MouseDownCanvas"
                Width="20" Height="18" VerticalAlignment="Center">

          <Ellipse x:Name="myEllipse" Canvas.Left="1" Canvas.Top="1" Width="16" Height="16"
                   Fill="Yellow" Stroke="Black" />



using System;
using System.Windows;
using System.Diagnostics;
using System.Windows.Shapes;
using System.Windows.Input;

namespace WpfApplication1
    public partial class Window1 : System.Windows.Window
        public Window1()

        void PreviewMouseDownCanvas(object sender, RoutedEventArgs e){ 

        void MouseDownCanvas(object sender, RoutedEventArgs e){ 


Related examples in the same category

1.Nested CanvasNested Canvas
2.Positioning on a CanvasPositioning on a Canvas
3.Canvas without ViewboxCanvas without Viewbox
4.Animation target Canvas Left, TopAnimation target Canvas Left, Top
5.Pixel Not SnappedPixel Not Snapped
6.Rotate ShapeRotate Shape
7.Canvas dependantCanvas dependant
8.Simple Canvas LayoutSimple Canvas Layout
12.Create a Scrollable Canvas ControlCreate a Scrollable Canvas Control
13.Create a Zoomable Canvas ControlCreate a Zoomable Canvas Control
14.Set control position for CanvasSet control position for Canvas
15.Canvas Positioning Properties SampleCanvas Positioning Properties Sample
16.Get position on a Canvas with Canvas.GetLeftGet position on a Canvas with Canvas.GetLeft