Skip to content

Instantly share code, notes, and snippets.

@philcleveland
Created December 12, 2013 21:30
Show Gist options
  • Save philcleveland/7935821 to your computer and use it in GitHub Desktop.
Save philcleveland/7935821 to your computer and use it in GitHub Desktop.
Drag and drop with Rx
var mouseDown = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseDown")
.Select(x => x.EventArgs.GetPosition(this));
var mouseUp = Observable.FromEventPattern<MouseButtonEventArgs>(this, "MouseUp")
.Select(x => x.EventArgs.GetPosition(this));
var mouseMove = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove")
.Select(x => x.EventArgs.GetPosition(this));
mouseMove.SkipUntil(mouseDown)
.TakeUntil(mouseUp)
.Subscribe(x =>
{
output.Text += string.Format("Drag&Drop yeah. {0}", x);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment