ChartDrawingToolbarButton.xaml.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. using MuchInfo.Chart.Infrastructure.Helpers;
  3. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. namespace MuchInfo.Chart.WPF.Controls.Drawing
  9. {
  10. /// <summary>
  11. /// ChartDrawingToolbarButton.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class ChartDrawingToolbarButton : UserControl
  14. {
  15. #region Fields
  16. private bool isPressed;
  17. private ChartDrawingToolbar parentBar;
  18. #endregion Fields
  19. #region Constructors
  20. public ChartDrawingToolbarButton(ChartDrawingToolbar parent)
  21. {
  22. this.isPressed = false;
  23. this.DrawingTarget = null;
  24. this.Command = PointerType.CursorWithData;
  25. this.ToolTipText = string.Empty;
  26. this.parentBar = parent;
  27. this.InitializeComponent();
  28. this.myText.Foreground = parent.Foreground;
  29. }
  30. #endregion Constructors
  31. #region Properties
  32. #region Public Properties
  33. public PointerType Command
  34. {
  35. get;
  36. set;
  37. }
  38. public IDrawingTool DrawingTarget
  39. {
  40. get;
  41. set;
  42. }
  43. public DrawingToolType DrawingToolType
  44. {
  45. get;
  46. set;
  47. }
  48. public bool IsPressed
  49. {
  50. get
  51. {
  52. return this.isPressed;
  53. }
  54. set
  55. {
  56. bool flag = value != this.isPressed;
  57. if (true)
  58. {
  59. this.isPressed = value;
  60. if (value)
  61. {
  62. this.Border.BorderBrush = new SolidColorBrush(ColorHelper.LightGray);
  63. var linearGradientBrush = new LinearGradientBrush();
  64. var gradientStop = new GradientStop { Offset = (0.0), Color = (Color.FromArgb(255, 90, 90, 90)) };
  65. linearGradientBrush.GradientStops.Add(gradientStop);
  66. gradientStop = new GradientStop { Offset = (0.0), Color = (Color.FromArgb(255, 70, 70, 70)) };
  67. linearGradientBrush.GradientStops.Add(gradientStop);
  68. this.Border.Background = (linearGradientBrush);
  69. this.myText.FontSize = parentBar.ParentChart.ChartFontSize + 1;
  70. this.myText.Margin = new Thickness(1.0, 0.0, 0.0, 0.0);
  71. }
  72. else
  73. {
  74. this.Border.BorderBrush = (new SolidColorBrush(ColorHelper.DimGray));
  75. this.Border.Background = (new SolidColorBrush(Colors.Transparent));
  76. this.myText.FontSize = parentBar.ParentChart.ChartFontSize;
  77. this.myText.Margin = new Thickness(2.0, 0.0, 10.0, 0.0);
  78. }
  79. }
  80. }
  81. }
  82. public string LabelText
  83. {
  84. get
  85. {
  86. return this.myText.Text;
  87. }
  88. set
  89. {
  90. this.myText.Text = (value);
  91. if (string.IsNullOrWhiteSpace(value))
  92. {
  93. this.myText.Visibility = Visibility.Collapsed;
  94. }
  95. else
  96. {
  97. this.myText.Visibility = Visibility.Visible;
  98. }
  99. }
  100. }
  101. public string ToolTipText
  102. {
  103. get;
  104. set;
  105. }
  106. #endregion Public Properties
  107. #endregion Properties
  108. #region Methods
  109. #region Internal Methods
  110. /// <summary>
  111. /// 触发button click事件
  112. /// </summary>
  113. internal void ButtonClick()
  114. {
  115. Border_MouseLeftButtonDown(null, null);
  116. }
  117. #endregion Internal Methods
  118. #region Private Methods
  119. private void Border_MouseEnter(object sender, MouseEventArgs e)
  120. {
  121. this.Border.MinWidth = this.Border.ActualWidth;
  122. this.Border.BorderBrush = (new SolidColorBrush(ColorHelper.LightGray));
  123. this.myText.FontSize = parentBar.ParentChart.ChartFontSize + 2;
  124. this.myText.Margin = new Thickness(1.0, 0.0, 0.0, 0.0);
  125. if (!string.IsNullOrWhiteSpace(this.ToolTipText))
  126. {
  127. //ChartToolTip.ShowTip(this, e, this.ToolTip);
  128. }
  129. }
  130. private void Border_MouseLeave(object sender, MouseEventArgs e)
  131. {
  132. this.Border.MinWidth = (0.0);
  133. if (this.isPressed)
  134. {
  135. this.Border.BorderBrush = (new SolidColorBrush(ColorHelper.LightGray));
  136. }
  137. else
  138. {
  139. this.Border.BorderBrush = (new SolidColorBrush(ColorHelper.DimGray));
  140. this.myText.FontSize = parentBar.ParentChart.ChartFontSize;
  141. this.myText.Margin = new Thickness(2.0, 0.0, 10.0, 0.0);
  142. }
  143. //if (!string.IsNullOrWhiteSpace(this.ToolTipText))
  144. //{
  145. // ChartToolTip.HideTip(this);
  146. //}
  147. }
  148. private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  149. {
  150. if (this.parentBar != null)
  151. {
  152. this.parentBar.ButtonSelectChanged(this);
  153. }
  154. //if (!string.IsNullOrWhiteSpace(this.ToolTipText))
  155. //{
  156. // ChartToolTip.HideTip(this);
  157. //}
  158. }
  159. #endregion Private Methods
  160. #endregion Methods
  161. }
  162. }