PageRenderTime 34ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/BaconographyWP8Core/View/ExtendedAppBar.xaml.cs

https://github.com/hippiehunter/Baconography
C# | 147 lines | 118 code | 24 blank | 5 comment | 2 complexity | 406dd624891ca1e306d0e6d85fff339a 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.Navigation;
  8. using Microsoft.Phone.Controls;
  9. using Microsoft.Phone.Shell;
  10. using System.Windows.Data;
  11. using System.Windows.Input;
  12. using System.Windows.Threading;
  13. using System.Windows.Media.Animation;
  14. using System.Windows.Media;
  15. using GalaSoft.MvvmLight.Command;
  16. namespace BaconographyWP8Core.View
  17. {
  18. public enum ExtendedAppMenuState
  19. {
  20. Extended,
  21. Collapsed
  22. }
  23. public partial class ExtendedAppBar : UserControl
  24. {
  25. public ExtendedAppBar()
  26. {
  27. InitializeComponent();
  28. DispatcherTimer timer = new DispatcherTimer();
  29. timer.Interval = TimeSpan.FromSeconds(5);
  30. timer.Tick += timer_Tick;
  31. overlayTimerRunning = true;
  32. timer.Start();
  33. }
  34. void timer_Tick(object sender, EventArgs e)
  35. {
  36. if (overlayEndTime < DateTime.Now)
  37. {
  38. overlayTimerRunning = false;
  39. ((DispatcherTimer)sender).Stop();
  40. Storyboard storyboard = new Storyboard();
  41. TranslateTransform trans = new TranslateTransform() { X = 1.0, Y = 1.0 };
  42. overlay.RenderTransformOrigin = new Point(0.5, 0.5);
  43. overlay.RenderTransform = trans;
  44. DoubleAnimation moveAnim = new DoubleAnimation();
  45. moveAnim.EasingFunction = new ExponentialEase();
  46. moveAnim.Duration = TimeSpan.FromMilliseconds(350);
  47. moveAnim.From = 0;
  48. moveAnim.To = -(overlay.ActualHeight);
  49. Storyboard.SetTarget(moveAnim, overlay);
  50. Storyboard.SetTargetProperty(moveAnim, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
  51. storyboard.Children.Add(moveAnim);
  52. storyboard.Begin();
  53. }
  54. }
  55. DateTime overlayEndTime = DateTime.Now.AddSeconds(5);
  56. bool overlayTimerRunning = false;
  57. internal void Interact()
  58. {
  59. overlayEndTime = DateTime.Now.AddSeconds(4);
  60. if (!overlayTimerRunning)
  61. {
  62. DispatcherTimer timer = new DispatcherTimer();
  63. timer.Interval = TimeSpan.FromSeconds(2);
  64. timer.Tick += timer_Tick;
  65. overlayTimerRunning = true;
  66. timer.Start();
  67. Storyboard storyboard = new Storyboard();
  68. TranslateTransform trans = new TranslateTransform() { X = 1.0, Y = 1.0 };
  69. overlay.RenderTransformOrigin = new Point(0.5, 0.5);
  70. overlay.RenderTransform = trans;
  71. DoubleAnimation moveAnim = new DoubleAnimation();
  72. moveAnim.EasingFunction = new ExponentialEase();
  73. moveAnim.Duration = TimeSpan.FromMilliseconds(350);
  74. moveAnim.From = -overlay.ActualHeight;
  75. moveAnim.To = 0;
  76. Storyboard.SetTarget(moveAnim, overlay);
  77. Storyboard.SetTargetProperty(moveAnim, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
  78. storyboard.Children.Add(moveAnim);
  79. storyboard.Begin();
  80. }
  81. }
  82. public double Opacity
  83. {
  84. get { return (double)GetValue(OpacityProperty); }
  85. set { SetValue(OpacityProperty, value); }
  86. }
  87. // Using a DependencyProperty as the backing store for Opacity. This enables animation, styling, binding, etc...
  88. public static readonly DependencyProperty OpacityProperty =
  89. DependencyProperty.Register("Opacity", typeof(double), typeof(ExtendedAppBar), new PropertyMetadata(0.66));
  90. public string Text
  91. {
  92. get { return (string)GetValue(TextProperty); }
  93. set { SetValue(TextProperty, value); }
  94. }
  95. // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
  96. public static readonly DependencyProperty TextProperty =
  97. DependencyProperty.Register("Text", typeof(string), typeof(ExtendedAppBar), new PropertyMetadata(""));
  98. public string LastButtonSymbol
  99. {
  100. get { return (string)GetValue(LastButtonSymbolProperty); }
  101. set { SetValue(LastButtonSymbolProperty, value); }
  102. }
  103. // Using a DependencyProperty as the backing store for LastButtonSymbol. This enables animation, styling, binding, etc...
  104. public static readonly DependencyProperty LastButtonSymbolProperty =
  105. DependencyProperty.Register("LastButtonSymbol", typeof(string), typeof(ExtendedAppBar), new PropertyMetadata(""));
  106. public ICommand LastButtonCommand
  107. {
  108. get { return (ICommand)GetValue(LastButtonCommandProperty); }
  109. set { SetValue(LastButtonCommandProperty, value); }
  110. }
  111. // Using a DependencyProperty as the backing store for LastButtonCommand. This enables animation, styling, binding, etc...
  112. public static readonly DependencyProperty LastButtonCommandProperty =
  113. DependencyProperty.Register("LastButtonCommand", typeof(ICommand), typeof(ExtendedAppBar), new PropertyMetadata(null));
  114. public string LastButtonText
  115. {
  116. get { return (string)GetValue(LastButtonTextProperty); }
  117. set { SetValue(LastButtonTextProperty, value); }
  118. }
  119. // Using a DependencyProperty as the backing store for LastButtonText. This enables animation, styling, binding, etc...
  120. public static readonly DependencyProperty LastButtonTextProperty =
  121. DependencyProperty.Register("LastButtonText", typeof(string), typeof(ExtendedAppBar), new PropertyMetadata(""));
  122. }
  123. }