| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using TeamAAS.FlowEditor.Models;
- namespace TeamAAS.FlowEditor.Controls
- {
- /// <summary>
- /// 节点控件
- /// </summary>
- public class NodeControl : System.Windows.Controls.Control
- {
- public const double DefaultWidth = 160;
- public const double DefaultHeight = 42;
- static NodeControl()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(NodeControl),
- new FrameworkPropertyMetadata(typeof(NodeControl)));
- }
- /// <summary>
- /// 获取绑定的 FlowNode
- /// </summary>
- public FlowNode GetNode()
- {
- return DataContext as FlowNode;
- }
- private Border _rectNode;
- private Border _loopNode;
- private Border _groupMainBorder;
- private Border _endMainBorder;
- private Border _exceptionBranchNode;
- private Path _diamondPath;
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- _rectNode = GetTemplateChild("RectNode") as Border;
- _loopNode = GetTemplateChild("LoopNode") as Border;
- _groupMainBorder = GetTemplateChild("GroupMainBorder") as Border;
- _endMainBorder = GetTemplateChild("EndMainBorder") as Border;
- _exceptionBranchNode = GetTemplateChild("ExceptionBranchNode") as Border;
- _diamondPath = GetTemplateChild("DiamondPath") as Path;
- UpdateDisabledVisual();
- }
- /// <summary>
- /// 根据 IsEnabled 更新禁用视觉(仅中间文本背景变灰,边框/色条/文字不变)
- /// </summary>
- public void UpdateDisabledVisual()
- {
- var node = GetNode();
- bool disabled = node == null || !node.IsEnabled;
- string key = disabled ? "SecondaryTextBrush" : "RegionBrush";
- if (_rectNode != null) _rectNode.SetResourceReference(BackgroundProperty, key);
- if (_loopNode != null) _loopNode.SetResourceReference(BackgroundProperty, key);
- if (_groupMainBorder != null) _groupMainBorder.SetResourceReference(BackgroundProperty, key);
- if (_endMainBorder != null) _endMainBorder.SetResourceReference(BackgroundProperty, key);
- if (_exceptionBranchNode != null) _exceptionBranchNode.SetResourceReference(BackgroundProperty, key);
- if (_diamondPath != null) _diamondPath.SetResourceReference(Path.FillProperty, key);
- }
- }
- }
|