1
0

MainPage.xaml.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Reactive.Linq;
  6. using System.Threading;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Animation;
  13. using System.Windows.Shapes;
  14. using Microsoft.Phone.Controls;
  15. using WindowsPhoneAgent7;
  16. namespace WindowsPhoneApp7
  17. {
  18. public partial class MainPage : PhoneApplicationPage
  19. {
  20. // Constructor
  21. public MainPage()
  22. {
  23. InitializeComponent();
  24. }
  25. private void button1_Click(object sender, RoutedEventArgs e)
  26. {
  27. new ScheduledAgent();
  28. var clock = MyExtensions.GetClock().AsQbservable().Select(_ => _).AsObservable();
  29. var input = Observable.FromEventPattern<TextChangedEventArgs>(textBox1, "TextChanged").Select(evt => ((TextBox)evt.Sender).Text).Throttle(TimeSpan.FromSeconds(.5)).DistinctUntilChanged();
  30. var xs = from word in input.StartWith("")
  31. from length in Observable.Return(word.Length).Delay(TimeSpan.FromSeconds(.5))
  32. select length;
  33. var res = xs.CombineLatest(clock, (len, now) => now.ToString() + " - Word length = " + len);
  34. res.ObserveOnDispatcher().Subscribe(s =>
  35. {
  36. label1.Text = s.ToString();
  37. });
  38. }
  39. }
  40. public class MyExtensions
  41. {
  42. public static IObservable<DateTime> GetClock()
  43. {
  44. return Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ => DateTime.Now);
  45. }
  46. }
  47. }