Knot.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /// <summary>
  17. /// Interaction logic for Knot.xaml
  18. /// </summary>
  19. public partial class Knot : UserControl
  20. {
  21. public Knot()
  22. {
  23. InitializeComponent();
  24. }
  25. public static readonly DependencyProperty KnotNameProperty = DependencyProperty.Register(
  26. "KnotName", typeof(string), typeof(Knot),
  27. new FrameworkPropertyMetadata("未知阀门", FrameworkPropertyMetadataOptions.AffectsRender));
  28. public static readonly DependencyProperty KnotDirectionProperty = DependencyProperty.Register(
  29. "KnotDirection", typeof(ValveDirection), typeof(Knot),
  30. new FrameworkPropertyMetadata(ValveDirection.ToBottom, FrameworkPropertyMetadataOptions.AffectsRender));
  31. public static readonly DependencyProperty KnotTypeProperty = DependencyProperty.Register(
  32. "KnotT", typeof(KnotType), typeof(Knot),
  33. new FrameworkPropertyMetadata(KnotType.Knot, FrameworkPropertyMetadataOptions.AffectsRender));
  34. /// <summary>
  35. /// Description
  36. /// </summary>
  37. public static readonly DependencyProperty ThroughInnerColorProperty =
  38. DependencyProperty.Register("ThroughInnerColor",
  39. typeof(string),
  40. typeof(Knot),
  41. new FrameworkPropertyMetadata("White"));
  42. /// <summary>
  43. /// A property wrapper for the <see cref="BalloonTextProperty"/>
  44. /// dependency property:<br/>
  45. /// Description
  46. /// </summary>
  47. public string ThroughInnerColor
  48. {
  49. get { return (string)GetValue(ThroughInnerColorProperty); }
  50. set { SetValue(ThroughInnerColorProperty, value); }
  51. }
  52. /// <summary>
  53. /// Description
  54. /// </summary>
  55. public static readonly DependencyProperty KnotElliColorProperty =
  56. DependencyProperty.Register("KnotElliColor",
  57. typeof(string),
  58. typeof(Knot),
  59. new FrameworkPropertyMetadata("Black"));
  60. /// <summary>
  61. /// A property wrapper for the <see cref="BalloonTextProperty"/>
  62. /// dependency property:<br/>
  63. /// Description
  64. /// </summary>
  65. public string KnotElliColor
  66. {
  67. get { return (string)GetValue(KnotElliColorProperty); }
  68. set { SetValue(KnotElliColorProperty, value); }
  69. }
  70. /// <summary>
  71. /// node or through tag
  72. /// </summary>
  73. public KnotType KnotT
  74. {
  75. get
  76. {
  77. return (KnotType)GetValue(KnotTypeProperty);
  78. }
  79. set
  80. {
  81. SetValue(KnotTypeProperty, value);
  82. }
  83. }
  84. /// <summary>
  85. /// direction of the valve
  86. /// </summary>
  87. public ValveDirection KnotDirection
  88. {
  89. get
  90. {
  91. return (ValveDirection)GetValue(KnotDirectionProperty);
  92. }
  93. set
  94. {
  95. SetValue(KnotDirectionProperty, value);
  96. }
  97. }
  98. /// <summary>
  99. /// valve name
  100. /// </summary>
  101. public string KnotName
  102. {
  103. get
  104. {
  105. return (string)GetValue(KnotNameProperty);
  106. }
  107. set
  108. {
  109. SetValue(KnotNameProperty, value);
  110. }
  111. }
  112. public PipeType PipeStyleType
  113. { get; set; }
  114. /// <summary>
  115. /// over rendering behavior
  116. /// </summary>
  117. /// <param name="drawingContext"></param>
  118. protected override void OnRender(DrawingContext drawingContext)
  119. {
  120. base.OnRender(drawingContext);
  121. switch (KnotDirection)
  122. {
  123. case ValveDirection.ToBottom:
  124. case ValveDirection.ToTop:
  125. rotateTransform.Angle = 90;
  126. break;
  127. case ValveDirection.ToLeft:
  128. break;
  129. case ValveDirection.ToRight:
  130. rotateTransform.Angle = 180;
  131. break;
  132. default:
  133. break;
  134. }
  135. if (KnotT == KnotType.Knot)
  136. {
  137. knotElli.Visibility = Visibility.Visible;
  138. throughPath.Visibility = Visibility.Hidden;
  139. }
  140. else
  141. {
  142. knotElli.Visibility = Visibility.Hidden;
  143. throughPath.Visibility = Visibility.Visible;
  144. }
  145. switch (PipeStyleType)
  146. {
  147. case Control.PipeType.DarkThick:
  148. knotElli.Stroke = Brushes.Black;
  149. pathThrough.Stroke = Brushes.Black;
  150. break;
  151. case Control.PipeType.GrayThick:
  152. knotElli.Stroke = Brushes.Gray;
  153. pathThrough.Stroke = Brushes.Gray;
  154. break;
  155. case Control.PipeType.Normal:
  156. default:
  157. //knotElli.Stroke = Brushes.Black;
  158. //pathThrough.Stroke = Brushes.Black;
  159. break;
  160. }
  161. }
  162. }
  163. public enum KnotType
  164. {
  165. Knot = 1,
  166. Through = 2
  167. }
  168. }