DropDownMenuWindow.cs
上传用户:huazai0421
上传日期:2008-05-30
资源大小:405k
文件大小:2k
源码类别:

SilverLight

开发平台:

C#

  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Controls.Primitives;
  4. namespace ESRI.ArcGIS.Samples
  5. {
  6. [TemplateVisualState(GroupName = "CommonStates", Name = "Visible")]
  7. [TemplateVisualState(GroupName = "CommonStates", Name = "Hidden")]
  8. [TemplatePart(Name = "Popup", Type = typeof(Popup))]
  9. public class DropDownMenuWindow : ContentControl
  10. {
  11. bool isVisible = false;
  12. public DropDownMenuWindow()
  13. {
  14. this.DefaultStyleKey = typeof(DropDownMenuWindow);
  15. }
  16. public override void OnApplyTemplate()
  17. {
  18. ChangeVisualState(false);
  19. base.OnApplyTemplate();
  20. }
  21. private void ChangeVisualState(bool useTransitions)
  22. {
  23. if (isVisible)
  24. {
  25. GoToState(useTransitions, "Visible");
  26. }
  27. else
  28. {
  29. GoToState(useTransitions, "Hidden");
  30. }
  31. }
  32. private bool GoToState(bool useTransitions, string stateName)
  33. {
  34. return VisualStateManager.GoToState(this, stateName, useTransitions);
  35. }
  36. /// <summary>
  37. /// Gets or sets IsVisible.
  38. /// </summary>
  39. public bool IsVisible
  40. {
  41. get { return isVisible; }
  42. set
  43. {
  44. isVisible = value;
  45. ChangeVisualState(true);
  46. }
  47. }
  48. /// <summary>
  49. /// Identifies the <see cref="VerticalOffset"/> dependency property.
  50. /// </summary>
  51. public static readonly DependencyProperty VerticalOffsetProperty =
  52. DependencyProperty.Register("VerticalOffset", typeof(double), typeof(DropDownMenuWindow),
  53. new PropertyMetadata(0.0));
  54. /// <summary>
  55. /// Gets or sets VerticalOffset.
  56. /// </summary>
  57. public double VerticalOffset
  58. {
  59. get { return (double)GetValue(VerticalOffsetProperty); }
  60. set { SetValue(VerticalOffsetProperty, value); }
  61. }
  62. /// <summary>
  63. /// Identifies the <see cref="HorizontalOffset"/> dependency property.
  64. /// </summary>
  65. public static readonly DependencyProperty HorizontalOffsetProperty =
  66. DependencyProperty.Register("HorizontalOffset", typeof(double), typeof(DropDownMenuWindow),
  67. new PropertyMetadata(0.0));
  68. /// <summary>
  69. /// Gets or sets HorizontalOffset.
  70. /// </summary>
  71. public double HorizontalOffset
  72. {
  73. get { return (double)GetValue(HorizontalOffsetProperty); }
  74. set { SetValue(HorizontalOffsetProperty, value); }
  75. }
  76. }
  77. }