工具栏整理

This commit is contained in:
艾竹
2023-04-02 12:01:46 +08:00
parent 02ebd056b3
commit 0701f25519
30 changed files with 1730 additions and 923 deletions

View File

@@ -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();

View 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;
}
}
}
}
}

View File

@@ -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");
}

View File

@@ -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);