PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/DataBoundApp1/MainPage.xaml.cs

https://bitbucket.org/JeffF/wp7codemashsmackdown2012
C# | 70 lines | 50 code | 10 blank | 10 comment | 5 complexity | a249892b634edf121084db844ecbc1db MD5 | raw file
  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.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using DataBoundApp1.ViewModels;
  13. using Microsoft.Phone.Controls;
  14. namespace DataBoundApp1
  15. {
  16. public partial class MainPage : PhoneApplicationPage
  17. {
  18. // Constructor
  19. public MainPage()
  20. {
  21. InitializeComponent();
  22. // Set the data context of the listbox control to the sample data
  23. DataContext = App.ViewModel;
  24. this.Loaded += new RoutedEventHandler(MainPage_Loaded);
  25. }
  26. // Handle selection changed on ListBox
  27. private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  28. {
  29. // If selected index is -1 (no selection) do nothing
  30. if (MainListBox.SelectedIndex == -1)
  31. return;
  32. // Navigate to the new page
  33. NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + ((SessionViewModel)MainListBox.SelectedItem).Uri, UriKind.Relative));
  34. // Reset selected index to -1 (no selection)
  35. MainListBox.SelectedIndex = -1;
  36. }
  37. // Load data for the ViewModel Sessions
  38. private void MainPage_Loaded(object sender, RoutedEventArgs e)
  39. {
  40. if (!App.ViewModel.IsDataLoaded)
  41. {
  42. App.ViewModel.LoadData();
  43. }
  44. }
  45. private void FavListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  46. {
  47. // If selected index is -1 (no selection) do nothing
  48. if (FavListBox.SelectedIndex == -1)
  49. return;
  50. // Navigate to the new page
  51. NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + ((SessionViewModel)FavListBox.SelectedItem).Uri, UriKind.Relative));
  52. // Reset selected index to -1 (no selection)
  53. FavListBox.SelectedIndex = -1;
  54. }
  55. private void txtSearchTerm_KeyUp(object sender, KeyEventArgs e)
  56. {
  57. App.ViewModel.FilterData(txtSearchTerm.Text);
  58. }
  59. }
  60. }