PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/toolkit/Microsoft.Phone.Controls.Toolkit/Common/VisualStates.cs

https://bitbucket.org/jeremejevs/word-steps
C# | 414 lines | 139 code | 64 blank | 211 comment | 8 complexity | 3f082c4685938387fd2a5e46f1c29e26 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.Diagnostics;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Media;
  10. #if WINDOWS_PHONE
  11. namespace Microsoft.Phone.Controls
  12. #else
  13. namespace System.Windows.Controls
  14. #endif
  15. {
  16. /// <summary>
  17. /// Names and helpers for visual states in the controls.
  18. /// </summary>
  19. internal static class VisualStates
  20. {
  21. #region GroupCommon
  22. /// <summary>
  23. /// Common state group.
  24. /// </summary>
  25. public const string GroupCommon = "CommonStates";
  26. /// <summary>
  27. /// Normal state of the Common state group.
  28. /// </summary>
  29. public const string StateNormal = "Normal";
  30. /// <summary>
  31. /// Normal state of the Common state group.
  32. /// </summary>
  33. public const string StateReadOnly = "ReadOnly";
  34. /// <summary>
  35. /// MouseOver state of the Common state group.
  36. /// </summary>
  37. public const string StateMouseOver = "MouseOver";
  38. /// <summary>
  39. /// Pressed state of the Common state group.
  40. /// </summary>
  41. public const string StatePressed = "Pressed";
  42. /// <summary>
  43. /// Disabled state of the Common state group.
  44. /// </summary>
  45. public const string StateDisabled = "Disabled";
  46. #endregion GroupCommon
  47. #region GroupFocus
  48. /// <summary>
  49. /// Focus state group.
  50. /// </summary>
  51. public const string GroupFocus = "FocusStates";
  52. /// <summary>
  53. /// Unfocused state of the Focus state group.
  54. /// </summary>
  55. public const string StateUnfocused = "Unfocused";
  56. /// <summary>
  57. /// Focused state of the Focus state group.
  58. /// </summary>
  59. public const string StateFocused = "Focused";
  60. #endregion GroupFocus
  61. #region GroupSelection
  62. /// <summary>
  63. /// Selection state group.
  64. /// </summary>
  65. public const string GroupSelection = "SelectionStates";
  66. /// <summary>
  67. /// Selected state of the Selection state group.
  68. /// </summary>
  69. public const string StateSelected = "Selected";
  70. /// <summary>
  71. /// Unselected state of the Selection state group.
  72. /// </summary>
  73. public const string StateUnselected = "Unselected";
  74. /// <summary>
  75. /// Selected inactive state of the Selection state group.
  76. /// </summary>
  77. public const string StateSelectedInactive = "SelectedInactive";
  78. #endregion GroupSelection
  79. #region GroupExpansion
  80. /// <summary>
  81. /// Expansion state group.
  82. /// </summary>
  83. public const string GroupExpansion = "ExpansionStates";
  84. /// <summary>
  85. /// Expanded state of the Expansion state group.
  86. /// </summary>
  87. public const string StateExpanded = "Expanded";
  88. /// <summary>
  89. /// Collapsed state of the Expansion state group.
  90. /// </summary>
  91. public const string StateCollapsed = "Collapsed";
  92. #endregion GroupExpansion
  93. #region GroupPopup
  94. /// <summary>
  95. /// Popup state group.
  96. /// </summary>
  97. public const string GroupPopup = "PopupStates";
  98. /// <summary>
  99. /// Opened state of the Popup state group.
  100. /// </summary>
  101. public const string StatePopupOpened = "PopupOpened";
  102. /// <summary>
  103. /// Closed state of the Popup state group.
  104. /// </summary>
  105. public const string StatePopupClosed = "PopupClosed";
  106. #endregion
  107. #region GroupValidation
  108. /// <summary>
  109. /// ValidationStates state group.
  110. /// </summary>
  111. public const string GroupValidation = "ValidationStates";
  112. /// <summary>
  113. /// The valid state for the ValidationStates group.
  114. /// </summary>
  115. public const string StateValid = "Valid";
  116. /// <summary>
  117. /// Invalid, focused state for the ValidationStates group.
  118. /// </summary>
  119. public const string StateInvalidFocused = "InvalidFocused";
  120. /// <summary>
  121. /// Invalid, unfocused state for the ValidationStates group.
  122. /// </summary>
  123. public const string StateInvalidUnfocused = "InvalidUnfocused";
  124. #endregion
  125. #region GroupExpandDirection
  126. /// <summary>
  127. /// ExpandDirection state group.
  128. /// </summary>
  129. public const string GroupExpandDirection = "ExpandDirectionStates";
  130. /// <summary>
  131. /// Down expand direction state of ExpandDirection state group.
  132. /// </summary>
  133. public const string StateExpandDown = "ExpandDown";
  134. /// <summary>
  135. /// Up expand direction state of ExpandDirection state group.
  136. /// </summary>
  137. public const string StateExpandUp = "ExpandUp";
  138. /// <summary>
  139. /// Left expand direction state of ExpandDirection state group.
  140. /// </summary>
  141. public const string StateExpandLeft = "ExpandLeft";
  142. /// <summary>
  143. /// Right expand direction state of ExpandDirection state group.
  144. /// </summary>
  145. public const string StateExpandRight = "ExpandRight";
  146. #endregion
  147. #region GroupHasItems
  148. /// <summary>
  149. /// HasItems state group.
  150. /// </summary>
  151. public const string GroupHasItems = "HasItemsStates";
  152. /// <summary>
  153. /// HasItems state of the HasItems state group.
  154. /// </summary>
  155. public const string StateHasItems = "HasItems";
  156. /// <summary>
  157. /// NoItems state of the HasItems state group.
  158. /// </summary>
  159. public const string StateNoItems = "NoItems";
  160. #endregion GroupHasItems
  161. #region GroupIncrease
  162. /// <summary>
  163. /// Increment state group.
  164. /// </summary>
  165. public const string GroupIncrease = "IncreaseStates";
  166. /// <summary>
  167. /// State enabled for increment group.
  168. /// </summary>
  169. public const string StateIncreaseEnabled = "IncreaseEnabled";
  170. /// <summary>
  171. /// State disabled for increment group.
  172. /// </summary>
  173. public const string StateIncreaseDisabled = "IncreaseDisabled";
  174. #endregion GroupIncrease
  175. #region GroupDecrease
  176. /// <summary>
  177. /// Decrement state group.
  178. /// </summary>
  179. public const string GroupDecrease = "DecreaseStates";
  180. /// <summary>
  181. /// State enabled for decrement group.
  182. /// </summary>
  183. public const string StateDecreaseEnabled = "DecreaseEnabled";
  184. /// <summary>
  185. /// State disabled for decrement group.
  186. /// </summary>
  187. public const string StateDecreaseDisabled = "DecreaseDisabled";
  188. #endregion GroupDecrease
  189. #region GroupIteractionMode
  190. /// <summary>
  191. /// InteractionMode state group.
  192. /// </summary>
  193. public const string GroupInteractionMode = "InteractionModeStates";
  194. /// <summary>
  195. /// Edit of the DisplayMode state group.
  196. /// </summary>
  197. public const string StateEdit = "Edit";
  198. /// <summary>
  199. /// Display of the DisplayMode state group.
  200. /// </summary>
  201. public const string StateDisplay = "Display";
  202. #endregion GroupIteractionMode
  203. #region GroupLocked
  204. /// <summary>
  205. /// DisplayMode state group.
  206. /// </summary>
  207. public const string GroupLocked = "LockedStates";
  208. /// <summary>
  209. /// Edit of the DisplayMode state group.
  210. /// </summary>
  211. public const string StateLocked = "Locked";
  212. /// <summary>
  213. /// Display of the DisplayMode state group.
  214. /// </summary>
  215. public const string StateUnlocked = "Unlocked";
  216. #endregion GroupLocked
  217. #region GroupActive
  218. /// <summary>
  219. /// Active state.
  220. /// </summary>
  221. public const string StateActive = "Active";
  222. /// <summary>
  223. /// Inactive state.
  224. /// </summary>
  225. public const string StateInactive = "Inactive";
  226. /// <summary>
  227. /// Active state group.
  228. /// </summary>
  229. public const string GroupActive = "ActiveStates";
  230. #endregion GroupActive
  231. #region GroupWatermark
  232. /// <summary>
  233. /// Non-watermarked state.
  234. /// </summary>
  235. public const string StateUnwatermarked = "Unwatermarked";
  236. /// <summary>
  237. /// Watermarked state.
  238. /// </summary>
  239. public const string StateWatermarked = "Watermarked";
  240. /// <summary>
  241. /// Watermark state group.
  242. /// </summary>
  243. public const string GroupWatermark = "WatermarkStates";
  244. #endregion GroupWatermark
  245. #region GroupCalendarButtonFocus
  246. /// <summary>
  247. /// Unfocused state for Calendar Buttons.
  248. /// </summary>
  249. public const string StateCalendarButtonUnfocused = "CalendarButtonUnfocused";
  250. /// <summary>
  251. /// Focused state for Calendar Buttons.
  252. /// </summary>
  253. public const string StateCalendarButtonFocused = "CalendarButtonFocused";
  254. /// <summary>
  255. /// CalendarButtons Focus state group.
  256. /// </summary>
  257. public const string GroupCalendarButtonFocus = "CalendarButtonFocusStates";
  258. #endregion GroupCalendarButtonFocus
  259. #region GroupBusyStatus
  260. /// <summary>
  261. /// Busy state for BusyIndicator.
  262. /// </summary>
  263. public const string StateBusy = "Busy";
  264. /// <summary>
  265. /// Idle state for BusyIndicator.
  266. /// </summary>
  267. public const string StateIdle = "Idle";
  268. /// <summary>
  269. /// Busyness group name.
  270. /// </summary>
  271. public const string GroupBusyStatus = "BusyStatusStates";
  272. #endregion
  273. #region GroupVisibility
  274. /// <summary>
  275. /// Visible state name for BusyIndicator.
  276. /// </summary>
  277. public const string StateVisible = "Visible";
  278. /// <summary>
  279. /// Hidden state name for BusyIndicator.
  280. /// </summary>
  281. public const string StateHidden = "Hidden";
  282. /// <summary>
  283. /// BusyDisplay group.
  284. /// </summary>
  285. public const string GroupVisibility = "VisibilityStates";
  286. #endregion
  287. /// <summary>
  288. /// Use VisualStateManager to change the visual state of the control.
  289. /// </summary>
  290. /// <param name="control">
  291. /// Control whose visual state is being changed.
  292. /// </param>
  293. /// <param name="useTransitions">
  294. /// A value indicating whether to use transitions when updating the
  295. /// visual state, or to snap directly to the new visual state.
  296. /// </param>
  297. /// <param name="stateNames">
  298. /// Ordered list of state names and fallback states to transition into.
  299. /// Only the first state to be found will be used.
  300. /// </param>
  301. public static void GoToState(Control control, bool useTransitions, params string[] stateNames)
  302. {
  303. Debug.Assert(control != null, "control should not be null!");
  304. Debug.Assert(stateNames != null, "stateNames should not be null!");
  305. Debug.Assert(stateNames.Length > 0, "stateNames should not be empty!");
  306. foreach (string name in stateNames)
  307. {
  308. if (VisualStateManager.GoToState(control, name, useTransitions))
  309. {
  310. break;
  311. }
  312. }
  313. }
  314. /// <summary>
  315. /// Gets the implementation root of the Control.
  316. /// </summary>
  317. /// <param name="dependencyObject">The DependencyObject.</param>
  318. /// <remarks>
  319. /// Implements Silverlight's corresponding internal property on Control.
  320. /// </remarks>
  321. /// <returns>Returns the implementation root or null.</returns>
  322. public static FrameworkElement GetImplementationRoot(DependencyObject dependencyObject)
  323. {
  324. Debug.Assert(dependencyObject != null, "DependencyObject should not be null.");
  325. return (1 == VisualTreeHelper.GetChildrenCount(dependencyObject)) ?
  326. VisualTreeHelper.GetChild(dependencyObject, 0) as FrameworkElement :
  327. null;
  328. }
  329. /// <summary>
  330. /// This method tries to get the named VisualStateGroup for the
  331. /// dependency object. The provided object's ImplementationRoot will be
  332. /// looked up in this call.
  333. /// </summary>
  334. /// <param name="dependencyObject">The dependency object.</param>
  335. /// <param name="groupName">The visual state group's name.</param>
  336. /// <returns>Returns null or the VisualStateGroup object.</returns>
  337. public static VisualStateGroup TryGetVisualStateGroup(DependencyObject dependencyObject, string groupName)
  338. {
  339. FrameworkElement root = GetImplementationRoot(dependencyObject);
  340. if (root == null)
  341. {
  342. return null;
  343. }
  344. return VisualStateManager.GetVisualStateGroups(root)
  345. .OfType<VisualStateGroup>()
  346. .Where(group => string.CompareOrdinal(groupName, group.Name) == 0)
  347. .FirstOrDefault();
  348. }
  349. }
  350. }