-
Notifications
You must be signed in to change notification settings - Fork 18
/
MainWindow.xaml.cs
41 lines (34 loc) · 1.05 KB
/
MainWindow.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
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Input;
namespace LinqQueries;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
IObservable<EventPattern<MouseEventArgs>> mouseMoves =
Observable.FromEventPattern<MouseEventArgs>(
background, nameof(background.MouseMove));
IObservable<Point> dragPositions =
from move in mouseMoves
where Mouse.Captured == background
select move.EventArgs.GetPosition(background);
dragPositions.Subscribe(point => { line.Points.Add(point); });
}
private void OnBackgroundMouseDown(object sender, MouseButtonEventArgs e)
{
background.CaptureMouse();
}
private void OnBackgroundMouseUp(object sender, MouseButtonEventArgs e)
{
if (Mouse.Captured == background)
{
background.ReleaseMouseCapture();
}
}
}