PageRenderTime 681ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/BaconographyWP8Core/View/PivotCountIndicator.xaml.cs

https://github.com/hippiehunter/Baconography
C# | 115 lines | 78 code | 10 blank | 27 comment | 4 complexity | 026aba0e506657bf185f81fbfcf5d500 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.Navigation;
  7. using Microsoft.Phone.Controls;
  8. using Microsoft.Phone.Shell;
  9. using System.Windows.Shapes;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Animation;
  14. using System.Windows.Controls;
  15. namespace BaconographyWP8.View
  16. {
  17. public partial class PivotCountIndicator : UserControl
  18. {
  19. /// <summary>
  20. /// Public ItemsCount property of type DependencyProperty
  21. /// </summary>
  22. public static readonly DependencyProperty ItemsCountProperty =
  23. DependencyProperty.Register("ItemsCount",
  24. typeof(int),
  25. typeof(PivotCountIndicator),
  26. new PropertyMetadata(OnItemsCountChanged));
  27. /// <summary>
  28. /// Public SelectedPivotIndex property of type DependencyProperty
  29. /// </summary>
  30. public static readonly DependencyProperty SelectedPivotIndexProperty =
  31. DependencyProperty.Register("SelectedPivotIndex",
  32. typeof(int),
  33. typeof(PivotCountIndicator),
  34. new PropertyMetadata(OnPivotIndexChanged));
  35. /// <summary>
  36. /// Constructor
  37. /// </summary>
  38. public PivotCountIndicator()
  39. {
  40. InitializeComponent();
  41. }
  42. /// <summary>
  43. /// Gets or sets number of pivot items
  44. /// </summary>
  45. public int ItemsCount
  46. {
  47. set { SetValue(ItemsCountProperty, value); }
  48. get { return (int)GetValue(ItemsCountProperty); }
  49. }
  50. /// <summary>
  51. /// Gets or sets index of selected pivot item
  52. /// </summary>
  53. public int SelectedPivotIndex
  54. {
  55. set { SetValue(SelectedPivotIndexProperty, value); }
  56. get { return (int)GetValue(SelectedPivotIndexProperty); }
  57. }
  58. /// <summary>
  59. /// OnItemsCountChanged property-changed handler
  60. /// </summary>
  61. private static void OnItemsCountChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  62. {
  63. (obj as PivotCountIndicator).SetCircles();
  64. }
  65. /// <summary>
  66. /// OnPivotIndexChanged property-changed handler
  67. /// </summary>
  68. private static void OnPivotIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  69. {
  70. (obj as PivotCountIndicator).AccentCircle();
  71. }
  72. /// <summary>
  73. /// Draws circles.
  74. /// </summary>
  75. private void SetCircles()
  76. {
  77. ellipsesPanel.Children.Clear();
  78. for (int i = 0; i < this.ItemsCount; i++)
  79. {
  80. Ellipse ellipse = new Ellipse() { Height = 10, Width = 10, Margin = new Thickness(2,0,0,0) };
  81. ellipsesPanel.Children.Add(ellipse);
  82. }
  83. this.AccentCircle();
  84. }
  85. /// <summary>
  86. /// Accents selected pivot item circle.
  87. /// </summary>
  88. private void AccentCircle()
  89. {
  90. int i = 0;
  91. foreach (var item in ellipsesPanel.Children)
  92. {
  93. if (item is Ellipse)
  94. {
  95. Ellipse ellipse = (Ellipse)item;
  96. if (i == this.SelectedPivotIndex)
  97. ellipse.Fill = (SolidColorBrush)Application.Current.Resources["PhoneForegroundBrush"];
  98. else
  99. ellipse.Fill = (SolidColorBrush)Application.Current.Resources["PhoneDisabledBrush"];
  100. i++;
  101. }
  102. }
  103. }
  104. }
  105. }