| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Markup;
- namespace LocalhostMES.Enums
- {
- public enum StationType
- {
- OP10,
- OP20L,
- OP20R,
- OP30L,
- OP30R,
- OP40L,
- OP40R,
- OP50L,
- OP50R,
- OP60L,
- OP60R,
- OP70L,
- OP70R,
- OP80L,
- OP80R
- }
- public class EnumBindingSourceExtension : MarkupExtension
- {
- private Type _enumType;
- public Type EnumType
- {
- get => _enumType;
- set
- {
- if ( value != _enumType )
- {
- if ( null != value )
- {
- Type enumType = Nullable.GetUnderlyingType(value) ?? value;
- if ( !enumType.IsEnum )
- throw new ArgumentException("Type must be for an Enum.");
- }
- _enumType = value;
- }
- }
- }
- public EnumBindingSourceExtension() { }
- public EnumBindingSourceExtension(Type enumType)
- {
- EnumType = enumType;
- }
- public override object ProvideValue(IServiceProvider serviceProvider)
- {
- if ( null == _enumType )
- throw new InvalidOperationException("The EnumType must be specified.");
- Type actualEnumType = Nullable.GetUnderlyingType(_enumType) ?? _enumType;
- Array enumValues = Enum.GetValues(actualEnumType);
- if ( actualEnumType == _enumType )
- return enumValues;
- Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
- enumValues.CopyTo(tempArray, 1);
- return tempArray;
- }
- }
- }
|