终端一体化运控平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

BeveledButton.xaml.cs 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace BPASmartClient.CustomResource.UserControls
  16. {
  17. /// <summary>
  18. /// BeveledButton.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class BeveledButton : UserControl
  21. {
  22. public BeveledButton()
  23. {
  24. InitializeComponent();
  25. }
  26. public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  27. {
  28. (d as BeveledButton).Refresh();
  29. }
  30. /// <summary>
  31. /// 依赖属性更改的委托
  32. /// </summary>
  33. private void Refresh()
  34. {
  35. this.poly.Fill = FillColor;
  36. this.poly.StrokeThickness = StrokeThickness;
  37. this.poly.Stroke = Stroke;
  38. }
  39. #region FillColor:填充颜色 依赖属性
  40. /// <summary>
  41. /// 填充颜色
  42. /// </summary>
  43. public Brush FillColor
  44. {
  45. get { return (Brush)GetValue(FillColorProperty); }
  46. set { SetValue(FillColorProperty, value); }
  47. }
  48. public static readonly DependencyProperty FillColorProperty =
  49. DependencyProperty.Register("FillColor", typeof(Brush), typeof(BeveledButton),
  50. new PropertyMetadata(default(Brush), new PropertyChangedCallback(OnPropertyChanged)));
  51. #endregion
  52. #region 外边线宽度
  53. /// <summary>
  54. /// 外边线宽度
  55. /// </summary>
  56. public int StrokeThickness
  57. {
  58. get { return (int)GetValue(StrokeThicknessProperty); }
  59. set { SetValue(StrokeThicknessProperty, value); }
  60. }
  61. public static readonly DependencyProperty StrokeThicknessProperty =
  62. DependencyProperty.Register("StrokeThickness", typeof(int), typeof(BeveledButton),
  63. new PropertyMetadata(0, new PropertyChangedCallback(OnPropertyChanged)));
  64. #endregion
  65. #region 外边框颜色
  66. /// <summary>
  67. /// 外边框颜色
  68. /// </summary>
  69. public Brush Stroke
  70. {
  71. get { return (Brush)GetValue(StrokeProperty); }
  72. set { SetValue(StrokeProperty, value); }
  73. }
  74. public static readonly DependencyProperty StrokeProperty =
  75. DependencyProperty.Register("Stroke", typeof(Brush), typeof(BeveledButton),
  76. new PropertyMetadata(default(Brush), new PropertyChangedCallback(OnPropertyChanged)));
  77. #endregion
  78. #region 输入文本
  79. public string Text
  80. {
  81. get { return (string)GetValue(TextProperty); }
  82. set { SetValue(TextProperty, value); }
  83. }
  84. public static readonly DependencyProperty TextProperty =
  85. DependencyProperty.Register("Text", typeof(string), typeof(BeveledButton),
  86. new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged)));
  87. #endregion
  88. #region 设置是否是平行四边形
  89. public bool IsParallelogram
  90. {
  91. get { return (bool)GetValue(IsParallelogramProperty); }
  92. set { SetValue(IsParallelogramProperty, value); }
  93. }
  94. public static readonly DependencyProperty IsParallelogramProperty =
  95. DependencyProperty.Register("IsParallelogram", typeof(bool), typeof(BeveledButton),
  96. new PropertyMetadata(false, new PropertyChangedCallback(OnPropertyChanged)));
  97. #endregion
  98. private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
  99. {
  100. PointCollection points = new PointCollection();
  101. points.Add(new Point(0, 0));
  102. points.Add(new Point(e.NewSize.Width - (e.NewSize.Height / 2), 0));
  103. points.Add(new Point(e.NewSize.Width, e.NewSize.Height));
  104. points.Add(new Point(IsParallelogram ? (e.NewSize.Height / 2) : 0, e.NewSize.Height));
  105. this.poly.Points = points;
  106. //this.tb.Text = Text;
  107. }
  108. }
  109. }