mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using AIStudio.Wpf.DiagramDesigner;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class EnumHelper : DependencyObject
|
|
{
|
|
public static Type GetEnum(DependencyObject obj)
|
|
{
|
|
return (Type)obj.GetValue(EnumProperty);
|
|
}
|
|
|
|
public static void SetEnum(DependencyObject obj, Type value)
|
|
{
|
|
obj.SetValue(EnumProperty, value);
|
|
}
|
|
|
|
// Using a DependencyProperty as the backing store for Enum. This enables animation, styling, binding, etc...
|
|
public static readonly DependencyProperty EnumProperty =
|
|
DependencyProperty.RegisterAttached("Enum", typeof(Type), typeof(EnumHelper), new PropertyMetadata(null, OnEnumChanged));
|
|
|
|
private static void OnEnumChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (DesignerHelper.IsInDesignMode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var control = sender as ItemsControl;
|
|
|
|
if (control != null)
|
|
{
|
|
if (e.NewValue != null)
|
|
{
|
|
var _enum = Enum.GetValues(e.NewValue as Type);
|
|
control.ItemsSource = _enum;
|
|
control.AlternationCount = _enum.Length;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|