PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/BaconographyWP8Core/View/ReplyViewPage.xaml.cs

https://github.com/hippiehunter/Baconography
C# | 144 lines | 128 code | 15 blank | 1 comment | 30 complexity | cf3c5b3d49eefe4e64c929a64e0b5736 MD5 | raw file
  1. using BaconographyPortable.Services;
  2. using BaconographyPortable.ViewModel;
  3. using BaconographyWP8Core;
  4. using Microsoft.Phone.Controls;
  5. using Microsoft.Practices.ServiceLocation;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Input;
  16. using System.Windows.Navigation;
  17. using Windows.Foundation;
  18. using Windows.Foundation.Collections;
  19. // The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
  20. namespace BaconographyWP8.View
  21. {
  22. [ViewUri("/BaconographyWP8Core;component/View/ReplyViewPage.xaml")]
  23. public sealed partial class ReplyViewPage : PhoneApplicationPage
  24. {
  25. INavigationService _navigationService;
  26. public ReplyViewPage()
  27. {
  28. this.InitializeComponent();
  29. _navigationService = ServiceLocator.Current.GetInstance<INavigationService>();
  30. _navigationService.GoBack();
  31. }
  32. protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  33. {
  34. if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
  35. {
  36. var vm = this.DataContext as ReplyViewModel;
  37. if (vm != null)
  38. vm.RefreshUser.Execute(null);
  39. }
  40. base.OnNavigatedTo(e);
  41. }
  42. protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
  43. {
  44. if (e.NavigationMode == NavigationMode.New && e.Uri.ToString() == "/BaconographyWP8Core;component/MainPage.xaml" && e.IsCancelable)
  45. e.Cancel = true;
  46. else
  47. {
  48. var vm = this.DataContext as ReplyViewModel;
  49. if (vm != null)
  50. vm.Cancel.Execute(vm);
  51. base.OnNavigatingFrom(e);
  52. }
  53. }
  54. private void ShowMoreButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
  55. {
  56. ShowExtended = !ShowExtended;
  57. }
  58. private void SendButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
  59. {
  60. object focusObj = FocusManager.GetFocusedElement();
  61. if (focusObj != null && focusObj is TextBox)
  62. {
  63. var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
  64. binding.UpdateSource();
  65. }
  66. var vm = this.DataContext as ReplyViewModel;
  67. if (vm != null)
  68. {
  69. vm.Submit.Execute(null);
  70. _navigationService.GoBack();
  71. }
  72. }
  73. public static readonly DependencyProperty ShowExtendedProperty =
  74. DependencyProperty.Register(
  75. "ShowExtended",
  76. typeof(bool),
  77. typeof(ReplyViewPage),
  78. new PropertyMetadata(false, OnShowExtendedPropertyChanged)
  79. );
  80. public bool ShowExtended
  81. {
  82. get
  83. {
  84. return (bool)GetValue(ShowExtendedProperty);
  85. }
  86. set
  87. {
  88. SetValue(ShowExtendedProperty, value);
  89. }
  90. }
  91. private static void OnShowExtendedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  92. {
  93. var view = (ReplyViewPage)d;
  94. view.ShowExtended = (bool)e.NewValue;
  95. }
  96. private void LoginButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
  97. {
  98. _navigationService.Navigate(typeof(LoginPageView), null);
  99. }
  100. private void TextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
  101. {
  102. var textbox = sender as TextBox;
  103. if (textbox != null)
  104. {
  105. var vm = this.DataContext as ReplyViewModel;
  106. if (vm != null)
  107. {
  108. if (vm.ReplyBody != textbox.Text)
  109. vm.ReplyBody = textbox.Text;
  110. }
  111. }
  112. }
  113. private void TextBox_SelectionChanged(object sender, RoutedEventArgs e)
  114. {
  115. var textbox = sender as TextBox;
  116. if (textbox != null)
  117. {
  118. var vm = this.DataContext as ReplyViewModel;
  119. if (vm != null)
  120. {
  121. if (vm.SelectionLength != textbox.SelectionLength)
  122. vm.SelectionLength = textbox.SelectionLength;
  123. if (vm.SelectionStart != textbox.SelectionStart)
  124. vm.SelectionStart = textbox.SelectionStart;
  125. }
  126. }
  127. }
  128. }
  129. }