FlatToolbarTextButton.xaml.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. /// FlatToolbarTextButton.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class FlatToolbarTextButton : UserControl
  12. {
  13. #region Fields
  14. private Border _seperatorBorder;
  15. private TextBlock _textLine2TextBlock;
  16. private string _toolTip;
  17. #endregion Fields
  18. #region Constructors
  19. public FlatToolbarTextButton()
  20. {
  21. this._toolTip = string.Empty;
  22. this._textLine2TextBlock = null;
  23. this.InitializeComponent();
  24. }
  25. #endregion Constructors
  26. #region Delegates
  27. public delegate void ClickEventHandler(MouseEventArgs e);
  28. #endregion Delegates
  29. #region Events
  30. public event FlatToolbarTextButton.ClickEventHandler Click;
  31. #endregion Events
  32. #region Properties
  33. #region Public Properties
  34. public Brush HighlightBrush
  35. {
  36. get
  37. {
  38. return this.theBorder.BorderBrush;
  39. }
  40. set
  41. {
  42. this.theBorder.BorderBrush = (value);
  43. }
  44. }
  45. public bool ShowSeperator
  46. {
  47. get
  48. {
  49. return this._seperatorBorder != null;
  50. }
  51. set
  52. {
  53. bool flag = value && this._seperatorBorder == null;
  54. if (flag)
  55. {
  56. this._seperatorBorder = new Border
  57. {
  58. IsHitTestVisible = (false),
  59. HorizontalAlignment = HorizontalAlignment.Right,
  60. VerticalAlignment = VerticalAlignment.Stretch,
  61. BorderBrush = new SolidColorBrush(ColorHelper.DarkGray),
  62. BorderThickness = new Thickness(1.0, 0.0, 0.0, 0.0),
  63. Margin = new Thickness(3.0, 4.0, 3.0, 4.0)
  64. };
  65. this._seperatorBorder.SetValue(Grid.ColumnProperty, 2);
  66. this.LayoutRoot.Children.Add(this._seperatorBorder);
  67. }
  68. else
  69. {
  70. flag = (!value & this._seperatorBorder != null);
  71. if (flag)
  72. {
  73. this.LayoutRoot.Children.Remove(this._seperatorBorder);
  74. this._seperatorBorder = null;
  75. }
  76. }
  77. }
  78. }
  79. public string Text
  80. {
  81. get
  82. {
  83. return this.theText.Text;
  84. }
  85. set
  86. {
  87. this.theText.Text = (value);
  88. }
  89. }
  90. public string TextLine2
  91. {
  92. get
  93. {
  94. bool flag = this._textLine2TextBlock == null;
  95. string result;
  96. if (flag)
  97. {
  98. result = "";
  99. }
  100. else
  101. {
  102. result = this._textLine2TextBlock.Text;
  103. }
  104. return result;
  105. }
  106. set
  107. {
  108. if (!string.IsNullOrWhiteSpace(value))
  109. {
  110. bool flag2 = this._textLine2TextBlock == null;
  111. if (flag2)
  112. {
  113. this._textLine2TextBlock = new TextBlock();
  114. _textLine2TextBlock.Margin = new Thickness(3.0, -2.0, 3.0, -1.0);
  115. this.stackText.Children.Add(this._textLine2TextBlock);
  116. }
  117. this._textLine2TextBlock.Text = value;
  118. }
  119. else
  120. {
  121. bool flag2 = this._textLine2TextBlock != null;
  122. if (flag2)
  123. {
  124. this.stackText.Children.Remove(this._textLine2TextBlock);
  125. this._textLine2TextBlock = null;
  126. }
  127. }
  128. }
  129. }
  130. public TextWrapping TextWrapping
  131. {
  132. get
  133. {
  134. return this.theText.TextWrapping;
  135. }
  136. set
  137. {
  138. this.theText.TextWrapping = (value);
  139. }
  140. }
  141. public TextBlock theTextBlock
  142. {
  143. get
  144. {
  145. return this.theText;
  146. }
  147. }
  148. #endregion Public Properties
  149. #endregion Properties
  150. #region Methods
  151. #region Protected Methods
  152. protected virtual void OnClick(MouseEventArgs e)
  153. {
  154. var handler = Click;
  155. if (handler != null) handler(e);
  156. }
  157. #endregion Protected Methods
  158. #region Private Methods
  159. private void theBorder_MouseEnter(object sender, MouseEventArgs e)
  160. {
  161. theBorder.BorderThickness = new Thickness(1.0);
  162. theBorder.Padding = new Thickness(0.0);
  163. //if (!string.IsNullOrWhiteSpace(_toolTip))
  164. //{
  165. // ChartToolTip.ShowTip(this, e, this._toolTip);
  166. //}
  167. }
  168. private void theBorder_MouseLeave(object sender, MouseEventArgs e)
  169. {
  170. theBorder.BorderThickness = new Thickness(0.0);
  171. theBorder.Padding = new Thickness(1.0);
  172. //if (!string.IsNullOrWhiteSpace(_toolTip))
  173. //{
  174. // ChartToolTip.HideTip(this);
  175. //}
  176. }
  177. private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  178. {
  179. OnClick(e);
  180. e.Handled = (true);
  181. }
  182. private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  183. {
  184. e.Handled = (true);
  185. }
  186. #endregion Private Methods
  187. #endregion Methods
  188. }
  189. }