mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-02 15:50:51 +08:00
覆盖默认定义
This commit is contained in:
@@ -23,4 +23,17 @@
|
||||
<Resource Include="A.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Views\Nodes\CustomDefinedNodeView.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="Views\Nodes\CustomDefinedNodeView.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo
|
||||
Children=new List<MenuItemViewModel>
|
||||
{
|
||||
new MenuItemViewModel(){Title = "Svg"},
|
||||
new MenuItemViewModel(){Title = "CustomDefinedNode"},
|
||||
new MenuItemViewModel(){Title = "PortlessLinks"},
|
||||
}
|
||||
},
|
||||
@@ -87,7 +88,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo
|
||||
},
|
||||
new MenuItemViewModel(){Title = "Algorithms",
|
||||
Children=new List<MenuItemViewModel>
|
||||
{
|
||||
{
|
||||
new MenuItemViewModel(){Title = "ReconnectLinksToClosestPorts"},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
{
|
||||
class CustomGroupViewModel : BaseViewModel
|
||||
{
|
||||
public CustomGroupViewModel()
|
||||
{
|
||||
Title = "Custom group";
|
||||
Info = "Creating your own custom groups is very easy!";
|
||||
|
||||
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, Text = "1" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node1);
|
||||
|
||||
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 300, Text = "2" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node2);
|
||||
|
||||
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 50, Text = "3" };
|
||||
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.GroupCommand.Execute(new List<DesignerItemViewModelBase> { node1, node2 });
|
||||
|
||||
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel() { Left = 50, Top = 50, Text = "1" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node1);
|
||||
|
||||
CustomDesignerItemViewModel node2 = new CustomDesignerItemViewModel() { Left = 300, Top = 300 };
|
||||
DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel() { Left = 300, Top = 300, Text = "2" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node2);
|
||||
|
||||
CustomDesignerItemViewModel node3 = new CustomDesignerItemViewModel() { Left = 300, Top = 50 };
|
||||
DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel() { Left = 300, Top = 50, Text = "3" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node3);
|
||||
|
||||
ConnectionViewModel connector1 = new ConnectionViewModel(node1.RightConnector, node2.TopConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
|
||||
@@ -39,70 +39,4 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public CustomDesignerItemViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new DesignerItemBase(this, Answer);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root)
|
||||
{
|
||||
base.Init(root);
|
||||
|
||||
this.ItemWidth = 150;
|
||||
this.ItemHeight = 80;
|
||||
InitConnector();
|
||||
}
|
||||
|
||||
protected override void InitConnector()
|
||||
{
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom));
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
if (designerbase is DesignerItemBase designer)
|
||||
{
|
||||
this.Answer = designer.Reserve;
|
||||
}
|
||||
}
|
||||
|
||||
private string _answer;
|
||||
public string Answer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _answer;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _answer, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
{
|
||||
public GroupingViewModel()
|
||||
{
|
||||
Title = "Simple";
|
||||
Info = "A simple example of AIStudio.Wpf.DiagramDesigner.";
|
||||
Title = "Grouping";
|
||||
Info = "You can (un)group nodes using CTRL+ALT+G.<br>" +
|
||||
"Currently, the library doesn't handle nested groups yet nor ports.";
|
||||
|
||||
DiagramViewModel = new DiagramViewModel();
|
||||
DiagramViewModel.PageSizeType = PageSizeType.Custom;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<dd:ColorBrushConverter x:Key="ColorBrushConverter" />
|
||||
|
||||
<DataTemplate DataType="{x:Type viewmodel:CustomDesignerItemViewModel}">
|
||||
<DataTemplate DataType="{x:Type viewmodel:CustomDefinedDesignerItemViewModel}">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" >
|
||||
<Grid Margin="10">
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
|
||||
{
|
||||
class CustomDefinedNodeViewModel : BaseViewModel
|
||||
{
|
||||
public CustomDefinedNodeViewModel()
|
||||
{
|
||||
Title = "Custom defined node";
|
||||
Info = "Creating your own defined design is very easy!";
|
||||
|
||||
DiagramViewModel = new DiagramViewModel();
|
||||
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
|
||||
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
|
||||
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, Text = "1" };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node1);
|
||||
|
||||
CustomDefinedDesignerItemViewModel node2 = new CustomDefinedDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 300 };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node2);
|
||||
|
||||
CustomDefinedDesignerItemViewModel node3 = new CustomDefinedDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 50 };
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(node3);
|
||||
|
||||
ConnectionViewModel connector1 = new ConnectionViewModel(DiagramViewModel, node1.RightConnector, node2.TopConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(connector1);
|
||||
|
||||
ConnectionViewModel connector2 = new ConnectionViewModel(DiagramViewModel, node2.BottomConnector, node3.BottomConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterOrthogonal);
|
||||
DiagramViewModel.DirectAddItemCommand.Execute(connector2);
|
||||
|
||||
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomDefinedDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public CustomDefinedDesignerItemViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDefinedDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDefinedDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CustomDefinedDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new DesignerItemBase(this, Answer);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root)
|
||||
{
|
||||
base.Init(root);
|
||||
|
||||
this.ItemWidth = 150;
|
||||
this.ItemHeight = 80;
|
||||
InitConnector();
|
||||
}
|
||||
|
||||
protected override void InitConnector()
|
||||
{
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));
|
||||
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom));
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
if (designerbase is DesignerItemBase designer)
|
||||
{
|
||||
this.Answer = designer.Reserve;
|
||||
}
|
||||
}
|
||||
|
||||
private string _answer;
|
||||
public string Answer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _answer;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _answer, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,25 @@
|
||||
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:local="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Views"
|
||||
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" >
|
||||
<dd:DiagramControl.ResourceDictionary>
|
||||
<ResourceDictionary>
|
||||
<!--覆盖系统默认样式-->
|
||||
<DataTemplate DataType="{x:Type dd:GroupDesignerItemViewModel}">
|
||||
<Grid Background="Red" IsHitTestVisible="{Binding IsHitTestVisible}">
|
||||
<TextBlock Text="Group"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</dd:DiagramControl.ResourceDictionary>
|
||||
</dd:DiagramControl>
|
||||
|
||||
<controls:TitleControl/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -7,13 +7,6 @@
|
||||
xmlns:controls="clr-namespace:AIStudio.Wpf.DiagramDesigner.Demo.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramDesigner.Demo;component/ViewModels/CustomDesignerItemViewModel.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<!-- Diagram Control -->
|
||||
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
|
||||
|
||||
@@ -6,19 +6,10 @@
|
||||
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">
|
||||
<UserControl.Resources>
|
||||
<DataTemplate DataType="{x:Type dd:GroupDesignerItemViewModel}">
|
||||
<Grid IsHitTestVisible="{Binding IsHitTestVisible}">
|
||||
<TextBlock Text="Group"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<!-- Diagram Control -->
|
||||
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
|
||||
</dd:DiagramControl>
|
||||
<dd:DiagramControl x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
|
||||
|
||||
<controls:TitleControl/>
|
||||
</Grid>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<UserControl x:Class="AIStudio.Wpf.DiagramDesigner.Demo.Views.CustomDefinedNodeView"
|
||||
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">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramDesigner.Demo;component/ViewModels/Nodes/CustomDefinedDesignerItemViewModel.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<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>
|
||||
/// CustomNodeView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class CustomDefinedNodeView : UserControl
|
||||
{
|
||||
public CustomDefinedNodeView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,36 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public DiagramControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (ResourceDictionary != null)
|
||||
{
|
||||
this.Resources.MergedDictionaries.Add(ResourceDictionary);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ResourceDictionaryProperty = DependencyProperty.Register(nameof(ResourceDictionary), typeof(ResourceDictionary), typeof(DiagramControl), new UIPropertyMetadata(null, OnResourceDictionaryChanged));
|
||||
|
||||
private static void OnResourceDictionaryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is DiagramControl diagram)
|
||||
{
|
||||
if (e.NewValue is ResourceDictionary dictionary)
|
||||
{
|
||||
diagram.Resources.MergedDictionaries.Add(dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceDictionary ResourceDictionary
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ResourceDictionary)GetValue(ResourceDictionaryProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(ResourceDictionaryProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ZoomValueProperty = DependencyProperty.Register(nameof(ZoomValue), typeof(double), typeof(DiagramControl), new UIPropertyMetadata(1d));
|
||||
@@ -42,6 +72,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
//DesignerCanvas myDesignerCanvas = sender as DesignerCanvas;
|
||||
//zoomBox.DesignerCanvas = myDesignerCanvas;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async void ScaleTransform_Changed(object sender, EventArgs e)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.Init(root);
|
||||
|
||||
this.IsHitTestVisible = false;
|
||||
this.IsHitTestVisible = true;
|
||||
}
|
||||
|
||||
protected override void InitConnector()
|
||||
|
||||
Reference in New Issue
Block a user