mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-14 13:16:38 +08:00
背景为渐变色的示例
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user