seyounth.hyosung.ty/Seyounth.Hyosung.Ava/Models/EnumBindingSourceExtension.cs

23 lines
573 B
C#
Raw Permalink Normal View History

using System;
using System.Windows.Markup;
using Avalonia.Markup.Xaml;
namespace Seyounth.Hyosung.UI.Helpers;
public class EnumBindingSourceExtension : MarkupExtension
{
public Type EnumType { get; private set; }
public EnumBindingSourceExtension(Type enumType)
{
if (enumType is null || !enumType.IsEnum)
throw new Exception("EnumType must be specified and be an Enum");
EnumType = enumType;
}
public override object? ProvideValue(IServiceProvider serviceProvider)
{
return Enum.GetValues(EnumType);
}
}