1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Reactive.Linq; 6 using System.Threading.Tasks; 7 using PortableLibraryProfile78_NuGet; 8 using Windows.Foundation; 9 using Windows.Foundation.Collections; 10 using Windows.UI.Xaml; 11 using Windows.UI.Xaml.Controls; 12 using Windows.UI.Xaml.Controls.Primitives; 13 using Windows.UI.Xaml.Data; 14 using Windows.UI.Xaml.Input; 15 using Windows.UI.Xaml.Media; 16 using Windows.UI.Xaml.Navigation; 17 18 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 19 20 namespace WindowsStoreApp8_NuGet 21 { 22 /// <summary> 23 /// An empty page that can be used on its own or navigated to within a Frame. 24 /// </summary> 25 public sealed partial class MainPage : Page 26 { MainPage()27 public MainPage() 28 { 29 this.InitializeComponent(); 30 } 31 32 /// <summary> 33 /// Invoked when this page is about to be displayed in a Frame. 34 /// </summary> 35 /// <param name="e">Event data that describes how this page was reached. The Parameter 36 /// property is typically used to configure the page.</param> OnNavigatedTo(NavigationEventArgs e)37 protected override void OnNavigatedTo(NavigationEventArgs e) 38 { 39 } 40 button1_Click(object sender, RoutedEventArgs e)41 private void button1_Click(object sender, RoutedEventArgs e) 42 { 43 var clock = MyExtensions.GetClock().AsQbservable().Select(_ => _).AsObservable(); 44 45 var txt = Observable.FromEventPattern<TextChangedEventArgs>(textBox1, "TextChanged").Select(evt => ((TextBox)evt.Sender).Text).Throttle(TimeSpan.FromSeconds(.5)).DistinctUntilChanged(); 46 47 var input = from t in Observable.Timer(TimeSpan.FromMilliseconds(100)) 48 from _ in txt 49 select _; 50 51 var xs = from word in input.StartWith("") 52 from length in Task.Run(async () => { await Task.Delay(250); return word.Length; }).AsAsyncOperation() 53 select length; 54 55 var res = xs.CombineLatest(clock, (len, now) => now.ToString() + " - Word length = " + len); 56 57 res.ObserveOnDispatcher().Subscribe(s => 58 { 59 label1.Text = s.ToString(); 60 }); 61 } 62 } 63 } 64