mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-14 13:16:38 +08:00
添加项目文件。
This commit is contained in:
136
AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.cs
Normal file
136
AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using AIStudio.Wpf.ADiagram.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Util.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
{
|
||||
public class FlowNode : DesignerItemViewModelBase
|
||||
{
|
||||
public FlowNode(NodeKinds kind) : base()
|
||||
{
|
||||
Kind = kind;
|
||||
Text = Kind.GetDescription();
|
||||
ShowText = true;
|
||||
ItemWidth = 80;
|
||||
ItemHeight = 40;
|
||||
|
||||
}
|
||||
|
||||
public FlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
ShowRotate = false;
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(parent, designerbase);
|
||||
|
||||
FlowNodeDesignerItem designer = designerbase as FlowNodeDesignerItem;
|
||||
this.Color = designer.Color;
|
||||
this.Kind = designer.Kind;
|
||||
this.StateImage = designer.StateImage;
|
||||
|
||||
if (this is MiddleFlowNode middle)
|
||||
{
|
||||
middle.UserIds = designer.UserIds;
|
||||
middle.RoleIds = designer.RoleIds;
|
||||
middle.ActType = designer.ActType;
|
||||
}
|
||||
}
|
||||
|
||||
private string _color;
|
||||
[Browsable(true)]
|
||||
public string Color
|
||||
{
|
||||
get { return _color; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _color, value);
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public NodeKinds Kind { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public string StateImage { get; set; }
|
||||
}
|
||||
|
||||
public class StartFlowNode : FlowNode
|
||||
{
|
||||
public StartFlowNode() : base(NodeKinds.Start)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public StartFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class EndFlowNode : FlowNode
|
||||
{
|
||||
public EndFlowNode() : base(NodeKinds.End)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EndFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class DecideFlowNode : FlowNode
|
||||
{
|
||||
public DecideFlowNode() : base(NodeKinds.Decide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DecideFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class COBeginFlowNode : FlowNode
|
||||
{
|
||||
public COBeginFlowNode() : base(NodeKinds.COBegin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public COBeginFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class COEndFlowNode : FlowNode
|
||||
{
|
||||
public COEndFlowNode() : base(NodeKinds.COEnd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public COEndFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
129
AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml
Normal file
129
AIStudio.Wpf.ADiagram/Demos/Flowchart/ViewModels/FlowNode.xaml
Normal file
@@ -0,0 +1,129 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:model="clr-namespace:AIStudio.Wpf.ADiagram.Models"
|
||||
xmlns:s="clr-namespace:Util.DiagramDesigner;assembly=Util.DiagramDesigner"
|
||||
xmlns:demo="clr-namespace:AIStudio.Wpf.ADiagram.Demos.Flowchart"
|
||||
xmlns:converter="clr-namespace:AIStudio.Wpf.ADiagram.Converters">
|
||||
<converter:HtmlColorConverter x:Key="HtmlColorConverter"/>
|
||||
<s:ColorBrushConverter x:Key="ColorBrushConverter"/>
|
||||
|
||||
<ControlTemplate x:Key="NormalNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="StartNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border CornerRadius="3" BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" CornerRadius="3,0,0,3" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="EndNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border CornerRadius="3" BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" CornerRadius="3,0,0,3" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="MiddleNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="DecideNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Path Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" StrokeThickness="1" Stretch="Fill" Data="M 0,0.25 L 0.5 0 L 1,0.25 L 0.5,0.5 Z"></Path>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
|
||||
<ControlTemplate x:Key="COBeginNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="COEndNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
|
||||
<Grid>
|
||||
<Border HorizontalAlignment="Left" Width="3" Background="{Binding Color}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style x:Key="CustomFlowNodeStyle" TargetType="{x:Type ContentControl}">
|
||||
<Setter Property="Template" Value="{StaticResource NormalNodeStyle}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="Start">
|
||||
<Setter Property="Template" Value="{StaticResource StartNodeStyle}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="End">
|
||||
<Setter Property="Template" Value="{StaticResource EndNodeStyle}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="Middle">
|
||||
<Setter Property="Template" Value="{StaticResource MiddleNodeStyle}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="Decide">
|
||||
<Setter Property="Template" Value="{StaticResource DecideNodeStyle}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="COBegin">
|
||||
<Setter Property="Template" Value="{StaticResource COBeginNodeStyle}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Kind}" Value="COEnd">
|
||||
<Setter Property="Template" Value="{StaticResource COEndNodeStyle}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
|
||||
<DataTemplate DataType="{x:Type model:FlowchartToolBoxData}">
|
||||
<Grid Width="{Binding Width}" Height="{Binding Height}">
|
||||
<Rectangle Name="Border"
|
||||
StrokeThickness="1"
|
||||
StrokeDashArray="2"
|
||||
Fill="Transparent"
|
||||
SnapsToDevicePixels="true"/>
|
||||
<Viewbox Stretch="Fill">
|
||||
<Grid>
|
||||
<ContentControl Style="{StaticResource CustomFlowNodeStyle}" Margin="2"/>
|
||||
<TextBlock Text="{Binding Text}" Margin="5" Foreground="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Grid>
|
||||
</Viewbox>
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter TargetName="Border" Property="Stroke" Value="Gray"/>
|
||||
</Trigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type demo:FlowNode}">
|
||||
<Grid IsHitTestVisible="False">
|
||||
<ContentControl Style="{StaticResource CustomFlowNodeStyle}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,60 @@
|
||||
using AIStudio.Wpf.ADiagram.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Util.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.ADiagram.Demos.Flowchart
|
||||
{
|
||||
public class MiddleFlowNode : FlowNode
|
||||
{
|
||||
public MiddleFlowNode() : base(NodeKinds.Middle)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MiddleFlowNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private List<string> _userIds = new List<string>();
|
||||
[Browsable(true)]
|
||||
[StyleName("UserIdsStyle")]
|
||||
public List<string> UserIds
|
||||
{
|
||||
get { return _userIds; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _userIds, value);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> _roleIds = new List<string>();
|
||||
[Browsable(true)]
|
||||
[StyleName("RoleIdsStyle")]
|
||||
public List<string> RoleIds
|
||||
{
|
||||
get { return _roleIds; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _roleIds, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _actType;
|
||||
[Browsable(true)]
|
||||
[StyleName("ActTypeStyle")]
|
||||
public string ActType
|
||||
{
|
||||
get { return _actType; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _actType, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user