PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-toolkit/PhoneToolkitSample/Samples/TransitionsSample.xaml.cs

https://bitbucket.org/jeremejevs/milk-manager
C# | 176 lines | 159 code | 13 blank | 4 comment | 5 complexity | 06a64dca84d3a566998aff4cc1dcd9be MD5 | raw file
  1. // (c) Copyright Microsoft Corporation.
  2. // This source is subject to the Microsoft Public License (Ms-PL).
  3. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  4. // All other rights reserved.
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Windows;
  9. using System.Windows.Data;
  10. using Microsoft.Phone.Controls;
  11. namespace PhoneToolkitSample.Samples
  12. {
  13. public partial class TransitionsSample : PhoneApplicationPage
  14. {
  15. public TransitionsSample()
  16. {
  17. DataContext = this;
  18. InitializeComponent();
  19. }
  20. public IList<string> Families
  21. {
  22. get
  23. {
  24. return new List<string>
  25. {
  26. "Roll",
  27. "Rotate",
  28. "Slide",
  29. "Swivel",
  30. "Turnstile"
  31. };
  32. }
  33. }
  34. private RotateTransition RotateTransitionElement(string mode)
  35. {
  36. RotateTransitionMode rotateTransitionMode = (RotateTransitionMode)Enum.Parse(typeof(RotateTransitionMode), mode, false);
  37. return new RotateTransition { Mode = rotateTransitionMode };
  38. }
  39. private SlideTransition SlideTransitionElement(string mode)
  40. {
  41. SlideTransitionMode slideTransitionMode = (SlideTransitionMode)Enum.Parse(typeof(SlideTransitionMode), mode, false);
  42. return new SlideTransition { Mode = slideTransitionMode };
  43. }
  44. private SwivelTransition SwivelTransitionElement(string mode)
  45. {
  46. SwivelTransitionMode swivelTransitionMode = (SwivelTransitionMode)Enum.Parse(typeof(SwivelTransitionMode), mode, false);
  47. return new SwivelTransition { Mode = swivelTransitionMode };
  48. }
  49. private TurnstileTransition TurnstileTransitionElement(string mode)
  50. {
  51. TurnstileTransitionMode turnstileTransitionMode = (TurnstileTransitionMode)Enum.Parse(typeof(TurnstileTransitionMode), mode, false);
  52. return new TurnstileTransition { Mode = turnstileTransitionMode };
  53. }
  54. private TransitionElement TransitionElement(string family, string mode)
  55. {
  56. switch (family)
  57. {
  58. case "Rotate":
  59. return RotateTransitionElement(mode);
  60. case "Slide":
  61. return SlideTransitionElement(mode);
  62. case "Swivel":
  63. return SwivelTransitionElement(mode);
  64. case "Turnstile":
  65. return TurnstileTransitionElement(mode);
  66. }
  67. return null;
  68. }
  69. private void See(object sender, RoutedEventArgs e)
  70. {
  71. string family = (string)Family.SelectedItem;
  72. string mode = (string)Mode.SelectedItem;
  73. TransitionElement transitionElement = null;
  74. if (family.Equals("Roll"))
  75. {
  76. transitionElement = new RollTransition();
  77. }
  78. else
  79. {
  80. transitionElement = TransitionElement(family, mode);
  81. }
  82. PhoneApplicationPage phoneApplicationPage = (PhoneApplicationPage)(((PhoneApplicationFrame)Application.Current.RootVisual)).Content;
  83. ITransition transition = transitionElement.GetTransition(phoneApplicationPage);
  84. transition.Completed += delegate
  85. {
  86. transition.Stop();
  87. };
  88. transition.Begin();
  89. }
  90. private void Forward(object sender, RoutedEventArgs e)
  91. {
  92. NavigationService.Navigate(new Uri("/Samples/NavigationTransitionSample1.xaml", UriKind.Relative));
  93. }
  94. private void FamilySelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  95. {
  96. string family = (string)Family.SelectedItem;
  97. Mode.Visibility = family.Equals("Roll") ? Visibility.Collapsed : Visibility.Visible;
  98. }
  99. }
  100. public class EnumConverter : IValueConverter
  101. {
  102. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  103. {
  104. string s = value as string;
  105. if (s == null)
  106. {
  107. return null;
  108. }
  109. switch (s)
  110. {
  111. case "Roll":
  112. return new List<string>();
  113. case "Rotate":
  114. return new List<string>
  115. {
  116. "In90Clockwise",
  117. "In90Counterclockwise",
  118. "In180Clockwise",
  119. "In180Counterclockwise",
  120. "Out90Clockwise",
  121. "Out90Counterclockwise",
  122. "Out180Clockwise",
  123. "Out180Counterclockwise"
  124. };
  125. case "Slide":
  126. return new List<string>
  127. {
  128. "SlideUpFadeIn",
  129. "SlideUpFadeOut",
  130. "SlideDownFadeIn",
  131. "SlideDownFadeOut",
  132. "SlideLeftFadeIn",
  133. "SlideLeftFadeOut",
  134. "SlideRightFadeIn",
  135. "SlideRightFadeOut"
  136. };
  137. case "Swivel":
  138. return new List<string>
  139. {
  140. "FullScreenIn",
  141. "FullScreenOut",
  142. "ForwardIn",
  143. "ForwardOut",
  144. "BackwardIn",
  145. "BackwardOut"
  146. };
  147. case "Turnstile":
  148. return new List<string>
  149. {
  150. "ForwardIn",
  151. "ForwardOut",
  152. "BackwardIn",
  153. "BackwardOut"
  154. };
  155. }
  156. return null;
  157. }
  158. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  159. {
  160. throw new NotSupportedException();
  161. }
  162. }
  163. }