Flowchart

This commit is contained in:
艾竹
2022-12-04 23:07:20 +08:00
parent dc42f75610
commit 0487857d7b
30 changed files with 1621 additions and 383 deletions

View File

@@ -69,7 +69,7 @@
</ResourceDictionary>
</Window.Resources>
<TabControl>
<TabItem Header="Custom">
<TabItem Header="Custom" >
<Grid x:Name="grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@@ -86,9 +86,9 @@
Width="3" />
<!-- Diagram Control -->
<dd:DiagramControl Grid.Column="1" x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<dd:DiagramControl Grid.Column="1" x:Name="diagram" DataContext="{Binding TabItem1ViewModel.DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<dd:PropertiesView Grid.Column="2" CustomSetting="True" SelectedObject="{Binding SelectedItem}" Width="200">
<dd:PropertiesView Grid.Column="2" CustomSetting="True" SelectedObject="{Binding TabItem1ViewModel.SelectedItem}" Width="200">
<dd:PropertiesView.Resources>
<Style x:Key="ActTypeStyle" TargetType="{x:Type ContentControl}">
@@ -112,7 +112,7 @@
<Grid DataContext="{Binding Path=DataContext,RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}">
<dd:MultiSelectComboBox BorderThickness="0" DisplayMemberPath="text" SelectedValuePath="value"
SelectedValues="{Binding UserIds}"
ItemsSource="{Binding Path=DataContext.Users,RelativeSource={RelativeSource AncestorType={x:Type Window}}}" ></dd:MultiSelectComboBox>
ItemsSource="{Binding Path=DataContext.TabItem1ViewModel.Users,RelativeSource={RelativeSource AncestorType={x:Type Window}}}" ></dd:MultiSelectComboBox>
</Grid>
</DataTemplate>
</Setter.Value>
@@ -125,7 +125,7 @@
<Grid DataContext="{Binding Path=DataContext,RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}">
<dd:MultiSelectComboBox BorderThickness="0" DisplayMemberPath="text" SelectedValuePath="value"
SelectedValues="{Binding RoleIds}"
ItemsSource="{Binding Path=DataContext.Roles,RelativeSource={RelativeSource AncestorType={x:Type Window}}}"></dd:MultiSelectComboBox>
ItemsSource="{Binding Path=DataContext.TabItem1ViewModel.Roles,RelativeSource={RelativeSource AncestorType={x:Type Window}}}"></dd:MultiSelectComboBox>
</Grid>
</DataTemplate>
</Setter.Value>
@@ -136,9 +136,40 @@
</Grid>
</TabItem>
<TabItem Header="Flowchart">
<dd:FlowchartEditor Users="{Binding Users}" Roles="{Binding Roles}">
</dd:FlowchartEditor>
<TabItem Header="Flowchart" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding TabItem2ViewModel.InputData}"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
Height="50"/>
<Button Grid.Column="1" Content="加载数据" Command="{Binding TabItem2ViewModel.SetDataCommand}"/>
<Button Grid.Column="2" Content="获取数据" Command="{Binding TabItem2ViewModel.GetDataCommand}"/>
<TextBox Grid.Column="3" Text="{Binding TabItem2ViewModel.OutputData}"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
Height="50"/>
</Grid>
<dd:FlowchartEditor Grid.Row="1" Data="{Binding TabItem2ViewModel.Data}"
GetDataFunc="{Binding TabItem2ViewModel.GetDataFunc,Mode=OneWayToSource}"
Users="{Binding TabItem2ViewModel.Users}"
Roles="{Binding TabItem2ViewModel.Roles}">
</dd:FlowchartEditor>
</Grid>
</TabItem>
</TabControl>
</Window>

View File

@@ -10,90 +10,16 @@ namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
{
class MainWindowViewModel : BindableBase
{
public ToolBoxViewModel ToolBoxViewModel
public TabItem1ViewModel TabItem1ViewModel
{
get; private set;
}
get; set;
} = new TabItem1ViewModel();
public DiagramViewModel DiagramViewModel
public TabItem2ViewModel TabItem2ViewModel
{
get; private set;
}
protected IDiagramServiceProvider _service
{
get
{
return DiagramServicesProvider.Instance.Provider;
}
}
public SelectableDesignerItemViewModelBase SelectedItem
{
get
{
return DiagramViewModel.SelectedItems?.FirstOrDefault();
}
}
private List<SelectOption> _users = new List<SelectOption>()
{
new SelectOption(){ value = "操作员1",text = "操作员1" },
new SelectOption(){ value = "操作员2",text = "操作员2" },
new SelectOption(){ value = "Admin",text = "Admin" },
};
public List<SelectOption> Users
{
get
{
return _users;
}
set
{
_users = value;
}
}
private List<SelectOption> _roles = new List<SelectOption>()
{
new SelectOption(){ value = "操作员",text = "操作员" },
new SelectOption(){ value = "管理员",text = "管理员" },
};
public List<SelectOption> Roles
{
get
{
return _roles;
}
set
{
_roles = value;
}
}
public MainWindowViewModel()
{
ToolBoxViewModel = new ToolBoxViewModel();
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.ShowGrid = true;
DiagramViewModel.GridCellSize = new Size(100, 60);
DiagramViewModel.GridMargin = 0d;
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
_service.DrawModeViewModel.VectorLineDrawMode = DrawMode.BoundaryConnectingLine;
DiagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
}
private void DiagramViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsSelected")
{
RaisePropertyChanged(nameof(SelectedItem));
}
}
get; set;
} = new TabItem2ViewModel();
}
}

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using AIStudio.Wpf.Flowchart;
using AIStudio.Wpf.Flowchart.ViewModels;
namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
{
public class TabItem1ViewModel: BindableBase
{
public ToolBoxViewModel ToolBoxViewModel
{
get; private set;
}
public DiagramViewModel DiagramViewModel
{
get; private set;
}
public SelectableDesignerItemViewModelBase SelectedItem
{
get
{
return DiagramViewModel.SelectedItems?.FirstOrDefault();
}
}
private List<SelectOption> _users = new List<SelectOption>()
{
new SelectOption(){ value = "操作员1",text = "操作员1" },
new SelectOption(){ value = "操作员2",text = "操作员2" },
new SelectOption(){ value = "Admin",text = "Admin" },
};
public List<SelectOption> Users
{
get
{
return _users;
}
set
{
_users = value;
}
}
private List<SelectOption> _roles = new List<SelectOption>()
{
new SelectOption(){ value = "操作员",text = "操作员" },
new SelectOption(){ value = "管理员",text = "管理员" },
};
public List<SelectOption> Roles
{
get
{
return _roles;
}
set
{
_roles = value;
}
}
public TabItem1ViewModel()
{
ToolBoxViewModel = new ToolBoxViewModel();
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.ShowGrid = true;
DiagramViewModel.GridCellSize = new Size(100, 60);
DiagramViewModel.GridMargin = 0d;
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DiagramViewModel.VectorLineDrawMode = DrawMode.BoundaryConnectingLine;
DiagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
}
private void DiagramViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsSelected")
{
RaisePropertyChanged(nameof(SelectedItem));
}
}
}
}

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Text;
using AIStudio.Wpf.Flowchart;
namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
{
public class TabItem2ViewModel : BindableBase
{
private List<SelectOption> _users = new List<SelectOption>()
{
new SelectOption(){ value = "操作员1",text = "操作员1" },
new SelectOption(){ value = "操作员2",text = "操作员2" },
new SelectOption(){ value = "Admin",text = "Admin" },
new SelectOption(){ value = "Bob",text = "Bob" },
new SelectOption(){ value = "Alice",text = "Alice" },
};
public List<SelectOption> Users
{
get
{
return _users;
}
set
{
_users = value;
}
}
private List<SelectOption> _roles = new List<SelectOption>()
{
new SelectOption(){ value = "操作员",text = "操作员" },
new SelectOption(){ value = "管理员",text = "管理员" },
new SelectOption(){ value = "Admin",text = "Admin" },
};
public List<SelectOption> Roles
{
get
{
return _roles;
}
set
{
_roles = value;
}
}
private Func<string> _getDataFunc;
public Func<string> GetDataFunc
{
get
{
return _getDataFunc;
}
set
{
SetProperty(ref _getDataFunc, value);
}
}
private string _inputData;
public string InputData
{
get
{
return _inputData;
}
set
{
SetProperty(ref _inputData, value);
}
}
private string _outputData;
public string OutputData
{
get
{
return _outputData;
}
set
{
SetProperty(ref _outputData, value);
}
}
private string _data = "{}";
public string Data
{
get
{
return _data;
}
set
{
SetProperty(ref _data, value);
}
}
public SimpleCommand GetDataCommand
{
get; private set;
}
public SimpleCommand SetDataCommand
{
get; private set;
}
public TabItem2ViewModel()
{
GetDataCommand = new SimpleCommand(GetDataExcute);
SetDataCommand = new SimpleCommand(SetDataExcute);
}
private void GetDataExcute(object obj)
{
OutputData = GetDataFunc();
}
private void SetDataExcute(object obj)
{
Data = "{}";
Data = InputData;
}
}
}