mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-01 14:46:36 +08:00
增加自定义 DesignerItemView 样式
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user