增加自定义 DesignerItemView 样式

This commit is contained in:
fan.yaying
2023-06-27 10:57:16 +08:00
parent ace3d631f5
commit 4968bbb5e7
4 changed files with 947 additions and 893 deletions

View File

@@ -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<Type, string> _styles = new ConcurrentDictionary<Type, string>();
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;
}
}
}
}