PipeControl.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. namespace Aitex.Core.UI.Control
  15. {
  16. public enum PipeType
  17. {
  18. Normal=1,
  19. DarkThick=2,
  20. GrayThick=3,
  21. }
  22. /// <summary>
  23. /// Interaction logic for PipeControl.xaml
  24. /// </summary>
  25. public partial class PipeControl : UserControl
  26. {
  27. public PipeControl()
  28. {
  29. InitializeComponent();
  30. }
  31. /// <summary>
  32. /// define dependency property
  33. /// </summary>
  34. public static readonly DependencyProperty PipeTypeProperty = DependencyProperty.Register(
  35. "PipeType", typeof(Orientation), typeof(PipeControl),
  36. new FrameworkPropertyMetadata(Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsRender));
  37. public static readonly DependencyProperty GasOnOffProperty = DependencyProperty.Register(
  38. "GasOnOff", typeof(bool), typeof(PipeControl),
  39. new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
  40. public static readonly DependencyProperty GasColorProperty = DependencyProperty.Register(
  41. "GasColor", typeof(Brush), typeof(PipeControl),
  42. new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender));
  43. /// <summary>
  44. /// pipe gas on/off state
  45. /// </summary>
  46. public bool GasOnOff
  47. {
  48. get
  49. {
  50. return (bool)this.GetValue(GasOnOffProperty);
  51. }
  52. set
  53. {
  54. this.SetValue(GasOnOffProperty, value);
  55. }
  56. }
  57. /// <summary>
  58. /// pipe gas on color
  59. /// </summary>
  60. public Brush GasColor
  61. {
  62. get
  63. {
  64. return (Brush)this.GetValue(GasColorProperty);
  65. }
  66. set
  67. {
  68. this.SetValue(GasColorProperty, value);
  69. }
  70. }
  71. /// <summary>
  72. /// set, get pipe control type
  73. /// </summary>
  74. public Orientation PipeType
  75. {
  76. get
  77. {
  78. return (Orientation)this.GetValue(PipeTypeProperty);
  79. }
  80. set
  81. {
  82. this.SetValue(PipeTypeProperty, value);
  83. }
  84. }
  85. public PipeType PipeStyleType
  86. { get; set; }
  87. private void LineSet(Line line1, double x1, double y1, double x2, double y2, PenLineCap startCap, PenLineCap endCap)
  88. {
  89. line1.X1 = x1;
  90. line1.X2 = x2;
  91. line1.Y1 = y1;
  92. line1.Y2 = y2;
  93. line1.StrokeStartLineCap = startCap;
  94. line1.StrokeEndLineCap = endCap;
  95. }
  96. /// <summary>
  97. /// override this function, to make this control property change visualable during design mode
  98. /// </summary>
  99. /// <param name="drawingContext"></param>
  100. protected override void OnRender(DrawingContext drawingContext)
  101. {
  102. base.OnRender(drawingContext);
  103. //render line color
  104. if (GasOnOff)
  105. {
  106. Line1Center.Stroke = GasColor;
  107. // Line1Border.Stroke = GasColor;
  108. }
  109. else
  110. {
  111. Line1Center.Stroke = Brushes.White;
  112. //Line1Border.Stroke = GasColor;
  113. }
  114. switch (PipeStyleType)
  115. {
  116. case Control.PipeType.DarkThick:
  117. Line1Center.StrokeThickness = 3;
  118. Line1Center.Stroke = Brushes.Black;
  119. break;
  120. case Control.PipeType.GrayThick:
  121. Line1Center.StrokeThickness = 3;
  122. Line1Center.Stroke = Brushes.Gray;
  123. break;
  124. case Control.PipeType.Normal:
  125. default:
  126. Line1Center.StrokeThickness = 1;
  127. // Line1Center.Stroke = Brushes.Black;
  128. break;
  129. }
  130. switch (PipeType)
  131. {
  132. case Orientation.Vertical:
  133. LineSet( Line1Center, Width / 2, 0, Width / 2, Height, PenLineCap.Round, PenLineCap.Round);
  134. this.Width = 20;
  135. break;
  136. case Orientation.Horizontal:
  137. LineSet( Line1Center, 0, Height / 2, Width, Height / 2, PenLineCap.Round, PenLineCap.Round);
  138. this.Height = 20;
  139. break;
  140. }
  141. }
  142. }
  143. }