mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-04 08:06:36 +08:00
整理整理
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Additionals
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Additionals
|
||||
{
|
||||
public class NewNameHelper
|
||||
{
|
||||
public static string GetNewName(IEnumerable<string> names, string firstName = null)
|
||||
{
|
||||
string result = string.Empty;
|
||||
int i = 1;
|
||||
if (firstName == null)
|
||||
{
|
||||
firstName = "新建-";
|
||||
}
|
||||
|
||||
result = firstName + i;
|
||||
|
||||
while (names.Any(o => { return o == result; })) //存在同名则继续累加
|
||||
{
|
||||
result = firstName + ++i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
internal static class SafeNativeMethods
|
||||
{
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int StrCmpLogicalW(string psz1, string psz2);
|
||||
}
|
||||
|
||||
public sealed class NaturalStringComparer : IComparer<string>
|
||||
{
|
||||
public int Compare(string a, string b)
|
||||
{
|
||||
return SafeNativeMethods.StrCmpLogicalW(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NaturalFileInfoNameComparer : IComparer<FileInfo>
|
||||
{
|
||||
public int Compare(FileInfo a, FileInfo b)
|
||||
{
|
||||
return SafeNativeMethods.StrCmpLogicalW(a.Name, b.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user