Knot.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. /// node or through tag
  54. /// </summary>
  55. public KnotType KnotT
  56. {
  57. get
  58. {
  59. return (KnotType)GetValue(KnotTypeProperty);
  60. }
  61. set
  62. {
  63. SetValue(KnotTypeProperty, value);
  64. }
  65. }
  66. /// <summary>
  67. /// direction of the valve
  68. /// </summary>
  69. public ValveDirection KnotDirection
  70. {
  71. get
  72. {
  73. return (ValveDirection)GetValue(KnotDirectionProperty);
  74. }
  75. set
  76. {
  77. SetValue(KnotDirectionProperty, value);
  78. }
  79. }
  80. /// <summary>
  81. /// valve name
  82. /// </summary>
  83. public string KnotName
  84. {
  85. get
  86. {
  87. return (string)GetValue(KnotNameProperty);
  88. }
  89. set
  90. {
  91. SetValue(KnotNameProperty, value);
  92. }
  93. }
  94. public PipeType PipeStyleType
  95. { get; set; }
  96. /// <summary>
  97. /// over rendering behavior
  98. /// </summary>
  99. /// <param name="drawingContext"></param>
  100. protected override void OnRender(DrawingContext drawingContext)
  101. {
  102. base.OnRender(drawingContext);
  103. switch (KnotDirection)
  104. {
  105. case ValveDirection.ToBottom:
  106. case ValveDirection.ToTop:
  107. rotateTransform.Angle = 90;
  108. break;
  109. case ValveDirection.ToLeft:
  110. break;
  111. case ValveDirection.ToRight:
  112. rotateTransform.Angle = 180;
  113. break;
  114. default:
  115. break;
  116. }
  117. if (KnotT == KnotType.Knot)
  118. {
  119. knotElli.Visibility = Visibility.Visible;
  120. throughPath.Visibility = Visibility.Hidden;
  121. }
  122. else
  123. {
  124. knotElli.Visibility = Visibility.Hidden;
  125. throughPath.Visibility = Visibility.Visible;
  126. }
  127. switch (PipeStyleType)
  128. {
  129. case Control.PipeType.DarkThick:
  130. knotElli.Stroke = Brushes.Black;
  131. pathThrough.Stroke = Brushes.Black;
  132. break;
  133. case Control.PipeType.GrayThick:
  134. knotElli.Stroke = Brushes.Gray;
  135. pathThrough.Stroke = Brushes.Gray;
  136. break;
  137. case Control.PipeType.Normal:
  138. default:
  139. knotElli.Stroke = Brushes.Black;
  140. pathThrough.Stroke = Brushes.Black;
  141. break;
  142. }
  143. }
  144. }
  145. public enum KnotType
  146. {
  147. Knot = 1,
  148. Through = 2
  149. }
  150. }