背景为渐变色的示例

This commit is contained in:
艾竹
2023-02-04 20:59:01 +08:00
parent 5b513370ff
commit 7f5bea55a8
10 changed files with 194 additions and 112 deletions

View File

@@ -300,15 +300,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
}
private ICommand _keyCommand;
public ICommand KeyCommand
{
get
{
return this._keyCommand ?? (this._keyCommand = new DelegateCommand<string>(para => this.KeyExecuted(para)));
}
}
private ICommand _formatCommand;
public ICommand FormatCommand
{
@@ -721,25 +712,20 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
public bool KeyExecuted(string para)
public bool KeyExecuted(KeyEventArgs e)
{
bool executed = true;
switch (para)
if (DiagramsViewModel?.DiagramViewModel?.ExecuteShortcut(e) == true)
{
return true;
}
var para = e.KeyboardDevice.Modifiers == ModifierKeys.None ? e.Key.ToString() : e.KeyboardDevice.Modifiers.ToString() + "+" + e.Key.ToString();
bool executed = true;
switch (para)
{
case "Control+A": SelectedAllExecuted(); break;
case "Control+C": CopyExecuted(); break;
case "Control+V": PasteExecuted(); break;
case "Control+X": CutExecuted(); break;
case "Control+O": OpenExecuted(); break;
case "Control+N": New_Executed(); break;
case "Control+S": SaveExecuted(); break;
case "Control+Z": UnDoExecuted(); break;
case "Control+Y": ReDoExecuted(); break;
case "Delete": DeleteExecuted(); break;
case "Left": LeftMoveExecuted(); break;
case "Right": RightMoveExecuted(); break;
case "Up": UpMoveExecuted(); break;
case "Down": DownMoveExecuted(); break;
case "Control+S": SaveExecuted(); break;
default: executed = false; break;
}

View File

@@ -41,7 +41,7 @@ namespace AIStudio.Wpf.DiagramApp
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
e.Handled = MainWindowViewModel.KeyExecuted(e.KeyboardDevice.Modifiers == ModifierKeys.None ? e.Key.ToString() : e.KeyboardDevice.Modifiers.ToString() + "+" + e.Key.ToString());
e.Handled = MainWindowViewModel.KeyExecuted(e);
}
private void HookEvents()

View File

@@ -58,6 +58,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo
new MenuItemViewModel(){Title = "Svg"},
new MenuItemViewModel(){Title = "CustomDefinedNode"},
new MenuItemViewModel(){Title = "PortlessLinks"},
new MenuItemViewModel(){Title = "GradientNode"},
}
},
new MenuItemViewModel(){Title = "Links",

View File

@@ -16,16 +16,18 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
DiagramViewModel.ColorViewModel = new ColorViewModel();
DiagramViewModel.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 50, Top = 80, Text = "1" };
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 350, Text = "2" };
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 100, Top = 300, Text = "2" };
DiagramViewModel.DirectAddItemCommand.Execute(node2);
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 400, Top = 100, Text = "3" };
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 200, Top = 80, Text = "3" };
DiagramViewModel.DirectAddItemCommand.Execute(node3);
ConnectionViewModel connector1 = new ConnectionViewModel(DiagramViewModel, node1.RightConnector, node2.LeftConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterNormal);
@@ -36,22 +38,19 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
connector2.AddLabel("Smooth");
DiagramViewModel.DirectAddItemCommand.Execute(connector2);
DefaultDesignerItemViewModel node11 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 50, Top = 450, Text = "11" };
DiagramViewModel.DirectAddItemCommand.Execute(node11);
DefaultDesignerItemViewModel node4 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 450, Top = 300, Text = "4" };
DiagramViewModel.DirectAddItemCommand.Execute(node4);
DefaultDesignerItemViewModel node12 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 250, Top = 648, Text = "12" };
DiagramViewModel.DirectAddItemCommand.Execute(node12);
DefaultDesignerItemViewModel node5 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 550, Top = 80, Text = "5" };
DiagramViewModel.DirectAddItemCommand.Execute(node5);
DefaultDesignerItemViewModel node13 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 400, Top = 450, Text = "13" };
DiagramViewModel.DirectAddItemCommand.Execute(node13);
ConnectionViewModel connector3 = new ConnectionViewModel(DiagramViewModel, node3.RightConnector, node4.LeftConnector, DrawMode.ConnectingLineBoundary, RouterMode.RouterNormal);
connector3.AddLabel("Boundary");
DiagramViewModel.DirectAddItemCommand.Execute(connector3);
ConnectionViewModel connector11 = new ConnectionViewModel(DiagramViewModel, node11.RightConnector, node12.LeftConnector, DrawMode.ConnectingLineBoundary, RouterMode.RouterNormal);
connector11.AddLabel("Boundary");
DiagramViewModel.DirectAddItemCommand.Execute(connector11);
ConnectionViewModel connector12 = new ConnectionViewModel(DiagramViewModel, node12.RightConnector, node13.LeftConnector, DrawMode.ConnectingLineCorner, RouterMode.RouterNormal);
connector12.AddLabel("Corner");
DiagramViewModel.DirectAddItemCommand.Execute(connector12);
ConnectionViewModel connector4 = new ConnectionViewModel(DiagramViewModel, node4.RightConnector, node5.LeftConnector, DrawMode.ConnectingLineCorner, RouterMode.RouterNormal);
connector4.AddLabel("Corner");
DiagramViewModel.DirectAddItemCommand.Execute(connector4);
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
}

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
class GradientNodeViewModel : BaseViewModel
{
public GradientNodeViewModel()
{
Title = "Gradient";
Info = "A node with a gradient background.";
DiagramViewModel = new DiagramViewModel();
DiagramViewModel.PageSizeType = PageSizeType.Custom;
DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
DiagramViewModel.ColorViewModel = new ColorViewModel();
DiagramViewModel.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 50, Top = 50 };
node1.ColorViewModel.FillColor.BrushType = BrushType.LinearGradientBrush;
node1.ColorViewModel.FillColor.GradientStop = new System.Collections.ObjectModel.ObservableCollection<GradientStop>()
{
new GradientStop(Colors.Red, 0),
new GradientStop(Colors.Yellow, 0.5),
new GradientStop(Colors.Blue, 1),
};
DiagramViewModel.DirectAddItemCommand.Execute(node1);
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 300 };
node2.ColorViewModel.FillColor.BrushType = BrushType.RadialGradientBrush;
node2.ColorViewModel.FillColor.GradientStop = new System.Collections.ObjectModel.ObservableCollection<GradientStop>()
{
new GradientStop(Colors.Red, 0),
new GradientStop(Colors.Yellow, 0.5),
new GradientStop(Colors.Blue, 1),
};
DiagramViewModel.DirectAddItemCommand.Execute(node2);
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 50 };
node3.ColorViewModel.FillColor.BrushType = BrushType.DrawingBrush;
DiagramViewModel.DirectAddItemCommand.Execute(node3);
ConnectionViewModel connector1 = new ConnectionViewModel(DiagramViewModel, node1.RightConnector, node2.LeftConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
ConnectionViewModel connector2 = new ConnectionViewModel(DiagramViewModel, node2.RightConnector, node3.RightConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterOrthogonal);
DiagramViewModel.DirectAddItemCommand.Execute(connector2);
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
}
}
}

View File

@@ -0,0 +1,16 @@
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.GradientNodeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram"
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!-- Diagram Control -->
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<controls:TitleControl/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AIStudio.Wpf.DiagramDesigner.Demo.Views
{
/// <summary>
/// GradientNodeView.xaml 的交互逻辑
/// </summary>
public partial class GradientNodeView : UserControl
{
public GradientNodeView()
{
InitializeComponent();
}
}
}

View File

@@ -94,78 +94,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.OnPreviewKeyDown(e);
if (DiagramViewModel.DiagramOption.ShortcutOption.SelectAll(e))
{
DiagramViewModel.SelectAllCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Copy(e))
{
DiagramViewModel.CopyCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Paste(e))
{
DiagramViewModel.PasteCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Cut(e))
{
DiagramViewModel.CutCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Undo(e))
{
DiagramViewModel.UndoCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Redo(e))
{
DiagramViewModel.RedoCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Delete(e))
{
DiagramViewModel.DeleteCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.LeftMove(e))
{
DiagramViewModel.LeftMoveCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.RightMove(e))
{
DiagramViewModel.RightMoveCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.UpMove(e))
{
DiagramViewModel.UpMoveCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.DownMove(e))
{
DiagramViewModel.DownMoveCommand.Execute(null);
e.Handled = true;
return;
}
else if (DiagramViewModel.DiagramOption.ShortcutOption.Group(e))
{
DiagramViewModel.GroupCommand.Execute(null);
e.Handled = true;
return;
}
}
}
}

View File

@@ -1748,6 +1748,74 @@ namespace AIStudio.Wpf.DiagramDesigner
}
#endregion
#region
public bool ExecuteShortcut(KeyEventArgs e)
{
if (DiagramOption.ShortcutOption.SelectAll(e))
{
SelectAllCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Copy(e))
{
CopyCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Paste(e))
{
PasteCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Cut(e))
{
CutCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Undo(e))
{
UndoCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Redo(e))
{
RedoCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Delete(e))
{
DeleteCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.LeftMove(e))
{
LeftMoveCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.RightMove(e))
{
RightMoveCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.UpMove(e))
{
UpMoveCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.DownMove(e))
{
DownMoveCommand.Execute(null);
return true;
}
else if (DiagramOption.ShortcutOption.Group(e))
{
GroupCommand.Execute(null);
return true;
}
return false;
}
#endregion
private void ExecuteLockCommand(object parameter)
{

View File

@@ -281,6 +281,8 @@ namespace AIStudio.Wpf.DiagramDesigner
void SetScreenScale();
bool ExecuteShortcut(KeyEventArgs e);
event PropertyChangedEventHandler PropertyChanged;
}