MainPage.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  18. namespace WindowsStoreApp8_NuGet
  19. {
  20. /// <summary>
  21. /// An empty page that can be used on its own or navigated to within a Frame.
  22. /// </summary>
  23. public sealed partial class MainPage : Page
  24. {
  25. public MainPage()
  26. {
  27. this.InitializeComponent();
  28. }
  29. /// <summary>
  30. /// Invoked when this page is about to be displayed in a Frame.
  31. /// </summary>
  32. /// <param name="e">Event data that describes how this page was reached. The Parameter
  33. /// property is typically used to configure the page.</param>
  34. protected override void OnNavigatedTo(NavigationEventArgs e)
  35. {
  36. }
  37. private void button1_Click(object sender, RoutedEventArgs e)
  38. {
  39. var clock = MyExtensions.GetClock().AsQbservable().Select(_ => _).AsObservable();
  40. var txt = Observable.FromEventPattern<TextChangedEventArgs>(textBox1, "TextChanged").Select(evt => ((TextBox)evt.Sender).Text).Throttle(TimeSpan.FromSeconds(.5)).DistinctUntilChanged();
  41. var input = from t in Observable.Timer(TimeSpan.FromMilliseconds(100))
  42. from _ in txt
  43. select _;
  44. var xs = from word in input.StartWith("")
  45. from length in Task.Run(async () => { await Task.Delay(250); return word.Length; }).AsAsyncOperation()
  46. select length;
  47. var res = xs.CombineLatest(clock, (len, now) => now.ToString() + " - Word length = " + len);
  48. res.ObserveOnDispatcher().Subscribe(s =>
  49. {
  50. label1.Text = s.ToString();
  51. });
  52. }
  53. }
  54. }