Skip to content

Instantly share code, notes, and snippets.

@atsushieno
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushieno/b5c8beb54312f6452262 to your computer and use it in GitHub Desktop.
Save atsushieno/b5c8beb54312f6452262 to your computer and use it in GitHub Desktop.
Xwt + Observable.FromEventPattern<T>()
using System;
using System.Linq;
using Xwt;
using System.Reactive.Linq;
namespace CSharpReactiveXwt
{
class MyWindow : Window
{
public static void Main (string[] args)
{
Application.Initialize ();
new MyWindow ().Show ();
Application.Run ();
}
public MyWindow ()
{
this.Closed += delegate { Application.Exit (); };
var label = new Label ();
var f = new Xwt.Frame () { WidthRequest = 200, HeightRequest = 200 };
var eo = Observable.FromEventPattern<MouseMovedEventArgs> (f, "MouseMoved")
//.Buffer (TimeSpan.FromSeconds (1));
.Sample (TimeSpan.FromSeconds (1));
//eo.Subscribe (v => Console.WriteLine (string.Join (";", v.Select (e => e.EventArgs).SelectMany (e => e.Position.ToString ()))));
eo.Subscribe (v => label.Text = v.EventArgs.Position.ToString ());
var vb = new VBox (); vb.PackStart (f); vb.PackStart (label);
Content = vb;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment