-
Notifications
You must be signed in to change notification settings - Fork 18
/
GroupJoin.xaml.cs
45 lines (39 loc) · 1.43 KB
/
GroupJoin.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace LinqQueries;
/// <summary>
/// Interaction logic for GroupJoin.xaml
/// </summary>
public partial class GroupJoin : Window
{
public GroupJoin()
{
InitializeComponent();
IObservable<EventPattern<MouseEventArgs>> downs =
Observable.FromEventPattern<MouseEventArgs>(
background, nameof(background.MouseDown));
IObservable<EventPattern<MouseEventArgs>> ups =
Observable.FromEventPattern<MouseEventArgs>(
background, nameof(background.MouseUp));
IObservable<EventPattern<MouseEventArgs>> allMoves =
Observable.FromEventPattern<MouseEventArgs>(
background, nameof(background.MouseMove));
var dragPointSets = from mouseDown in downs
join move in allMoves
on ups equals allMoves into m
select m.Select(e => e.EventArgs.GetPosition(background));
dragPointSets.Subscribe(dragPoints =>
{
var currentLine = new Polyline { Stroke = Brushes.Black, StrokeThickness = 2 };
background.Children.Add(currentLine);
dragPoints.Subscribe(point =>
{
currentLine.Points.Add(point);
});
});
}
}