From 4968bbb5e734add5eb5e89d67f82060386e04e9b Mon Sep 17 00:00:00 2001 From: "fan.yaying" Date: Tue, 27 Jun 2023 10:57:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=20DesignerItemView=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/DesignerCanvas.cs | 16 +- .../DesignerItemsControlItemStyleSelector.cs | 51 +- .../Themes/DiagramControl.xaml | 890 ++++++++++++++++++ .../UserControls/DiagramControl.xaml | 883 +---------------- 4 files changed, 947 insertions(+), 893 deletions(-) create mode 100644 AIStudio.Wpf.DiagramDesigner/Themes/DiagramControl.xaml diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index fcb4748..2ddc30e 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -83,7 +83,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } } - + private BlockItemsContainer _sourceItemsContainer; public BlockItemsContainer SourceItemsContainer { @@ -250,7 +250,7 @@ namespace AIStudio.Wpf.DiagramDesigner this.Loaded += DesignerCanvas_Loaded; this.IsVisibleChanged += DesignerCanvas_IsVisibleChanged; - this.DataContextChanged += DesignerCanvas_DataContextChanged; + this.DataContextChanged += DesignerCanvas_DataContextChanged; } private void DesignerCanvas_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) @@ -275,7 +275,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e) + protected void DesignerCanvas_Loaded(object sender, RoutedEventArgs e) { Mediator.Instance.Register(this); this.Focus(); @@ -575,7 +575,7 @@ namespace AIStudio.Wpf.DiagramDesigner } else if (SourceItemsContainer != null) { - ( _viewModel as IBlockDiagramViewModel).FinishNearBlock(new System.Collections.Generic.List { SourceItemsContainer.DragObject }); + (_viewModel as IBlockDiagramViewModel).FinishNearBlock(new System.Collections.Generic.List { SourceItemsContainer.DragObject }); ExitCursor(); } @@ -662,7 +662,7 @@ namespace AIStudio.Wpf.DiagramDesigner DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null && (dragObject.ContentType == typeof(BlockDesignerItemViewModel) || dragObject.ContentType.IsSubclassOf(typeof(BlockDesignerItemViewModel)))) { - var position = e.GetPosition(this); + var position = e.GetPosition(this); BlockDesignerItemViewModel itemBase = Activator.CreateInstance(dragObject.ContentType) as BlockDesignerItemViewModel; itemBase.Text = dragObject.Text; @@ -682,8 +682,8 @@ namespace AIStudio.Wpf.DiagramDesigner itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2); (_viewModel as IBlockDiagramViewModel)?.PreviewNearBlock(new System.Collections.Generic.List { itemBase }); - } - + } + base.OnDragOver(e); } @@ -741,7 +741,7 @@ namespace AIStudio.Wpf.DiagramDesigner } itemBase.Left = Math.Max(0, position.X - itemBase.GetItemWidth() / 2); - itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2); + itemBase.Top = Math.Max(0, position.Y - itemBase.GetItemHeight() / 2); _viewModel.AddCommand.Execute(itemBase); if (itemBase is BlockDesignerItemViewModel block) diff --git a/AIStudio.Wpf.DiagramDesigner/StyleSelectors/DesignerItemsControlItemStyleSelector.cs b/AIStudio.Wpf.DiagramDesigner/StyleSelectors/DesignerItemsControlItemStyleSelector.cs index 3867a5f..cef24d0 100644 --- a/AIStudio.Wpf.DiagramDesigner/StyleSelectors/DesignerItemsControlItemStyleSelector.cs +++ b/AIStudio.Wpf.DiagramDesigner/StyleSelectors/DesignerItemsControlItemStyleSelector.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Concurrent; using System.Windows; using System.Windows.Controls; @@ -20,6 +18,25 @@ namespace AIStudio.Wpf.DiagramDesigner private set; } + private static ConcurrentDictionary _styles = new ConcurrentDictionary(); + + public void RegisterDesignerItemControlItemStyle(Type type, string resourceName) + { + if (_styles.ContainsKey(type)) + { + throw new InvalidOperationException($"{type}-{resourceName} already exists"); + } + _styles.TryAdd(type, resourceName); + } + + public void RegisterDesignerItemControlItemStyle(Type type, string resourceName, bool isCover) + { + if (_styles.ContainsKey(type)) + { + _styles[type] = resourceName; + } + _styles.TryAdd(type, resourceName); + } public override Style SelectStyle(object item, DependencyObject container) { @@ -27,6 +44,28 @@ namespace AIStudio.Wpf.DiagramDesigner if (itemsControl == null) throw new InvalidOperationException("DesignerItemsControlItemStyleSelector : Could not find ItemsControl"); + if (!_styles.IsNullOrEmpty()) + { + var type = item.GetType(); + if (_styles.ContainsKey(type)) + { + return (Style)itemsControl.FindResource(_styles[type]); + } + + foreach (var styleItem in _styles) + { + if (type.IsSubclassOf(styleItem.Key)) + { + return (Style)itemsControl.FindResource(styleItem.Value); + } + + if (type.IsAssignableFrom(styleItem.Key)) + { + return (Style)itemsControl.FindResource(styleItem.Value); + } + } + } + if (item is GifImageItemViewModel) { return (Style)itemsControl.FindResource("gifimageItemStyle"); @@ -46,13 +85,13 @@ namespace AIStudio.Wpf.DiagramDesigner { return (Style)itemsControl.FindResource("designerItemStyle"); } - + if (item is ConnectionViewModel) { return (Style)itemsControl.FindResource("connectorItemStyle"); - } + } return null; } - } + } } diff --git a/AIStudio.Wpf.DiagramDesigner/Themes/DiagramControl.xaml b/AIStudio.Wpf.DiagramDesigner/Themes/DiagramControl.xaml new file mode 100644 index 0000000..ca93d4f --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner/Themes/DiagramControl.xaml @@ -0,0 +1,890 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml index 9e22d2a..8387b0f 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml @@ -10,889 +10,14 @@ mc:Ignorable="d" HorizontalAlignment="Center" VerticalAlignment="Center" d:DesignHeight="300" d:DesignWidth="300"> + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +