FlatToolbatTextAndImageButton.xaml.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using MuchInfo.Chart.Infrastructure.Helpers;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. namespace MuchInfo.Chart.Infrastructure.Controls
  7. {
  8. /// <summary>
  9. /// FlatToolbatTextAndImageButton.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class FlatToolbatTextAndImageButton : UserControl
  12. {
  13. #region Fields
  14. private bool _enabled;
  15. private string _toolTip;
  16. #endregion Fields
  17. #region Constructors
  18. public FlatToolbatTextAndImageButton()
  19. {
  20. this._toolTip = "";
  21. this._enabled = true;
  22. this.InitializeComponent();
  23. }
  24. #endregion Constructors
  25. #region Delegates
  26. public delegate void ClickEventHandler(MouseEventArgs e);
  27. #endregion Delegates
  28. #region Events
  29. public event FlatToolbatTextAndImageButton.ClickEventHandler Click;
  30. #endregion Events
  31. #region Properties
  32. #region Public Properties
  33. public bool Enabled
  34. {
  35. get
  36. {
  37. return this._enabled;
  38. }
  39. set
  40. {
  41. bool flag = value != this._enabled;
  42. if (flag)
  43. {
  44. this._enabled = value;
  45. flag = this._enabled;
  46. if (flag)
  47. {
  48. this.theImage.Visibility = Visibility.Visible;
  49. this.theText.Foreground = new SolidColorBrush(Colors.Black);
  50. }
  51. else
  52. {
  53. this.theText.Foreground = new SolidColorBrush(Colors.Gray);
  54. }
  55. }
  56. }
  57. }
  58. public Brush HighlightBrush
  59. {
  60. get
  61. {
  62. return this.theBorder.BorderBrush;
  63. }
  64. set
  65. {
  66. this.theBorder.BorderBrush = value;
  67. }
  68. }
  69. public ImageSource Image
  70. {
  71. get
  72. {
  73. return this.theImage.Source;
  74. }
  75. set
  76. {
  77. this.theImage.Source = value;
  78. }
  79. }
  80. public Stretch ImageStretch
  81. {
  82. get
  83. {
  84. return this.theImage.Stretch;
  85. }
  86. set
  87. {
  88. this.theImage.Stretch = value;
  89. }
  90. }
  91. public TextAlignment Orientation
  92. {
  93. get
  94. {
  95. bool flag = this.theStack.Children[0] == this.theImage;
  96. TextAlignment result;
  97. if (flag)
  98. {
  99. result = TextAlignment.Left;
  100. }
  101. else
  102. {
  103. result = (TextAlignment)2;
  104. }
  105. return result;
  106. }
  107. set
  108. {
  109. switch (value)
  110. {
  111. case (TextAlignment)1:
  112. this.theStack.Children.Clear();
  113. this.theStack.Children.Add(this.theImage);
  114. this.theStack.Children.Add(this.theText);
  115. break;
  116. case (TextAlignment)2:
  117. this.theStack.Children.Clear();
  118. this.theStack.Children.Add(this.theText);
  119. this.theStack.Children.Add(this.theImage);
  120. break;
  121. }
  122. }
  123. }
  124. public bool ShowSeperator
  125. {
  126. get
  127. {
  128. return this.Seperator.Visibility == 0;
  129. }
  130. set
  131. {
  132. if (value)
  133. {
  134. this.Seperator.Visibility = Visibility.Visible;
  135. }
  136. else
  137. {
  138. this.Seperator.Visibility = Visibility.Collapsed;
  139. }
  140. }
  141. }
  142. public string Text
  143. {
  144. get
  145. {
  146. return this.theText.Text;
  147. }
  148. set
  149. {
  150. this.theText.Text = value;
  151. }
  152. }
  153. public TextBlock TheTextBlock
  154. {
  155. get
  156. {
  157. return this.theText;
  158. }
  159. }
  160. #endregion Public Properties
  161. #endregion Properties
  162. #region Methods
  163. #region Protected Methods
  164. protected virtual void OnClick(MouseEventArgs e)
  165. {
  166. ClickEventHandler handler = Click;
  167. if (handler != null) handler(e);
  168. }
  169. #endregion Protected Methods
  170. #region Private Methods
  171. private void theBorder_MouseEnter(object sender, MouseEventArgs e)
  172. {
  173. this.theBorder.BorderThickness = new Thickness(1.0);
  174. this.theBorder.Padding = new Thickness(0.0);
  175. //if (!string.IsNullOrWhiteSpace(_toolTip))
  176. //{
  177. // ChartToolTip.ShowTip(this, e, this._toolTip);
  178. //}
  179. }
  180. private void theBorder_MouseLeave(object sender, MouseEventArgs e)
  181. {
  182. theBorder.BorderThickness = new Thickness(0.0);
  183. theBorder.Padding = new Thickness(1.0);
  184. //if (!string.IsNullOrWhiteSpace(_toolTip))
  185. //{
  186. // ChartToolTip.HideTip(this);
  187. //}
  188. }
  189. private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  190. {
  191. bool flag = this._enabled;
  192. if (flag)
  193. {
  194. OnClick(e);
  195. e.Handled = true;
  196. }
  197. }
  198. private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  199. {
  200. bool flag = this._enabled;
  201. if (flag)
  202. {
  203. e.Handled = true;
  204. }
  205. }
  206. #endregion Private Methods
  207. #endregion Methods
  208. }
  209. }