rendered paste body var mouseMoveEvent = Observable.FromEvent<MouseEventArgs>( this, "MouseMove" );
var mouseLeftButtonDown = Observable.FromEvent<MouseButtonEventArgs>( this, "MouseLeftButtonDown" );
var mouseLeftButtonUp = Observable.FromEvent<MouseButtonEventArgs>( this, "MouseLeftButtonUp" );
var clickingEvents = from pos in mouseLeftButtonDown
.Let(mm => mm.Zip(mm.Skip(1), (prev, cur) =>
new
{
IsClick = true,
X2 = cur.EventArgs.GetPosition( this ).X,
X1 = prev.EventArgs.GetPosition( this ).X,
Y2 = cur.EventArgs.GetPosition( this ).Y,
Y1 = prev.EventArgs.GetPosition( this ).Y
} ) ).Repeat()
select pos;
var draggingEvents = from pos in mouseMoveEvent.SkipUntil( mouseLeftButtonDown )
.SkipUntil(mouseLeftButtonDown)
.SkipUntil(mouseLeftButtonUp)
.Let( mm => mm.Zip( mm.Skip( 1 ), ( prev, cur ) =>
new
{
X2 = cur.EventArgs.GetPosition( this ).X,
X1 = prev.EventArgs.GetPosition( this ).X,
Y2 = cur.EventArgs.GetPosition( this ).Y,
Y1 = prev.EventArgs.GetPosition( this ).Y
} ) ).Repeat()
select pos;
clickingEvents.Subscribe(
p =>
{
Line line = new Line();
line.StrokeThickness = 2;
line.Stroke = new SolidColorBrush( Colors.Black );
line.X1 = p.X1;
line.Y1 = p.Y1;
line.X2 = p.X2;
line.Y2 = p.Y2;
this.LayoutRoot.Children.Add( line );
});
draggingEvents.Subscribe(
p =>
{
Line line = new Line();
line.StrokeThickness = 2;
line.Stroke = new SolidColorBrush( Colors.Red );
line.X1 = p.X1;
line.Y1 = p.Y1;
line.X2 = p.X2;
line.Y2 = p.Y2;
this.LayoutRoot.Children.Add( line );
});