MainPage.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Navigation;
  8. using Microsoft.Phone.Controls;
  9. using Microsoft.Phone.Shell;
  10. using WindowsPhoneApp8.Resources;
  11. using PortableLibraryProfile7;
  12. using System.Reactive.Linq;
  13. using WindowsPhoneAgent8;
  14. namespace WindowsPhoneApp8
  15. {
  16. public partial class MainPage : PhoneApplicationPage
  17. {
  18. // Constructor
  19. public MainPage()
  20. {
  21. InitializeComponent();
  22. // Sample code to localize the ApplicationBar
  23. //BuildLocalizedApplicationBar();
  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. // Sample code for building a localized ApplicationBar
  40. //private void BuildLocalizedApplicationBar()
  41. //{
  42. // // Set the page's ApplicationBar to a new instance of ApplicationBar.
  43. // ApplicationBar = new ApplicationBar();
  44. // // Create a new button and set the text value to the localized string from AppResources.
  45. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
  46. // appBarButton.Text = AppResources.AppBarButtonText;
  47. // ApplicationBar.Buttons.Add(appBarButton);
  48. // // Create a new menu item with the localized string from AppResources.
  49. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
  50. // ApplicationBar.MenuItems.Add(appBarMenuItem);
  51. //}
  52. }
  53. }