添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
// XAML 中可直接写 {conv:EnumBindingSource {x:Type local:MyEnum}}
|
||||
public class EnumBindingSourceExtension : MarkupExtension
|
||||
{
|
||||
public Type EnumType { get; set; }
|
||||
public bool UseDescription { get; set; } = true;
|
||||
|
||||
public EnumBindingSourceExtension() { }
|
||||
|
||||
public EnumBindingSourceExtension(Type enumType)
|
||||
{
|
||||
EnumType = enumType;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (EnumType == null || !EnumType.IsEnum) return null;
|
||||
|
||||
var values = Enum.GetValues(EnumType).Cast<Enum>();
|
||||
return values.Select(v => new EnumItem
|
||||
{
|
||||
Value = v,
|
||||
Description = UseDescription ? EnumHelper.GetEnumDescription(v) : v.ToString()
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class EnumItem
|
||||
{
|
||||
public Enum Value { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int IntValue => Convert.ToInt32(Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user