mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-05-03 06:21:30 +08:00
工具栏整理
This commit is contained in:
@@ -126,19 +126,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (this.startPoint.HasValue && this.endPoint.HasValue)
|
||||
{
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polygon
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), pointList);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
itemBase.PointDesignerItemViewModels.ForEach(p =>
|
||||
{
|
||||
p.ParentId = itemBase.Id;
|
||||
_viewModel.Add(p);
|
||||
});
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Text)
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Text)
|
||||
{
|
||||
TextDesignerItemViewModel itemBase = new TextDesignerItemViewModel();
|
||||
Point position = e.GetPosition(this);
|
||||
@@ -149,15 +137,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polygon
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), pointList);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), new List<Point> { this.startPoint.Value, this.endPoint.Value });
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
itemBase.PointDesignerItemViewModels.ForEach(p =>
|
||||
{
|
||||
p.ParentId = itemBase.Id;
|
||||
_viewModel.Add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
this._service.DrawModeViewModel.ResetDrawMode();
|
||||
|
||||
50
AIStudio.Wpf.DiagramDesigner/Helpers/EnumHelper.cs
Normal file
50
AIStudio.Wpf.DiagramDesigner/Helpers/EnumHelper.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EnumHelper : DependencyObject
|
||||
{
|
||||
public static Type GetEnum(DependencyObject obj)
|
||||
{
|
||||
return (Type)obj.GetValue(EnumProperty);
|
||||
}
|
||||
|
||||
public static void SetEnum(DependencyObject obj, Type value)
|
||||
{
|
||||
obj.SetValue(EnumProperty, value);
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for Enum. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty EnumProperty =
|
||||
DependencyProperty.RegisterAttached("Enum", typeof(Type), typeof(EnumHelper), new PropertyMetadata(null, OnEnumChanged));
|
||||
|
||||
private static void OnEnumChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (DesignerHelper.IsInDesignMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var control = sender as ItemsControl;
|
||||
|
||||
if (control != null)
|
||||
{
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
var _enum = Enum.GetValues(e.NewValue as Type);
|
||||
control.ItemsSource = _enum;
|
||||
control.AlternationCount = _enum.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,9 +364,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return IsReadOnly == false;
|
||||
}
|
||||
|
||||
private void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
protected virtual void FontViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "FontCase")
|
||||
if (e.PropertyName == nameof(FontViewModel.FontCase))
|
||||
{
|
||||
RaisePropertyChanged("Text");
|
||||
}
|
||||
|
||||
@@ -24,20 +24,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
|
||||
PointDesignerItemViewModels = new List<PointDesignerItemViewModel>();
|
||||
ConnectionPoints.ForEach((Action<Point>)(p => {
|
||||
var item = new PointDesignerItemViewModel(p);
|
||||
PointDesignerItemViewModels.Add((PointDesignerItemViewModel)item);
|
||||
}));
|
||||
|
||||
PointDesignerItemViewModels.ForEach(p => p.PropertyChanged += PointDesignerItemViewModel_PropertyChanged);
|
||||
}
|
||||
|
||||
public List<PointDesignerItemViewModel> PointDesignerItemViewModels
|
||||
{
|
||||
get; set;
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
private List<Point> _connectionPoints;
|
||||
@@ -68,10 +55,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
foreach (var connector in PointDesignerItemViewModels)
|
||||
{
|
||||
connector.ShowConnectors = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,17 +65,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private void PointDesignerItemViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Left) || e.PropertyName == nameof(Top))
|
||||
{
|
||||
UpdatePoints();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePoints()
|
||||
{
|
||||
ConnectionPoints = PointDesignerItemViewModels.Select(p => p.CurrentLocation).ToList();
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
|
||||
Reference in New Issue
Block a user