Page1.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reactive.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using PortableLibraryProfile78_NuGet;
  17. namespace WpfXbapApp45_NuGet
  18. {
  19. /// <summary>
  20. /// Interaction logic for Page1.xaml
  21. /// </summary>
  22. public partial class Page1 : Page
  23. {
  24. public Page1()
  25. {
  26. InitializeComponent();
  27. }
  28. private void button1_Click(object sender, RoutedEventArgs e)
  29. {
  30. //
  31. // Note: Local Qbservable compilation doesn't work in partial trust XBAP! (Cut for Rx v2.0 RTM.)
  32. //
  33. // var clock = MyExtensions.GetClock().AsQbservable().Select(_ => _).AsObservable();
  34. //
  35. var clock = MyExtensions.GetClock();
  36. var input = Observable.FromEventPattern<TextChangedEventArgs>(textBox1, "TextChanged").Select(evt => ((TextBox)evt.Sender).Text).Throttle(TimeSpan.FromSeconds(.5)).DistinctUntilChanged();
  37. var xs = from word in input.StartWith("")
  38. from length in Task.Run(async () => { await Task.Delay(250); return word.Length; })
  39. select length;
  40. var res = xs.CombineLatest(clock, (len, now) => now.ToString() + " - Word length = " + len);
  41. res.ObserveOnDispatcher().Subscribe(s =>
  42. {
  43. label1.Text = s.ToString();
  44. });
  45. }
  46. }
  47. }