I’m trying to create a custom control with a value bound to an Enum value. I’d like it to be reusable with different Enum types. Is it possible to create a custom control that derives from BaseField<Enum>? I seem to be stuck with ArgumentNullException: Value cannot be null. Parameter name: property looping over and over as soon as I add my minimal control anywhere in the UI Builder.
My attempts were based on the source code of the EnumField, but it seems to rely on some code marked as internal. Are there any other examples available?
Thanks for looking into this! I’ve tried something similar but then discovered that many utilities to obtain Enum options and display them as strings are also marked as internal. I tried copying these utilities into my code but hit a wall further along and abandoned this approach.
My second approach was to inherit from the EnumField and hide the input, but that didn’t work because I had no means to switch to the next/previous value of the Enum. Also it didn’t feel right.
I ended up creating an abstract class with the signature MyCustomEnumField<T> : BaseField<T> where T : System.Enum. This contains all my code, and I need to make an empty concrete class for each of my enums, but I can live with that.
This works for me; however, in the long run, it would be really nice if UI Toolkit provided a BaseEnumField, similar to how it does have a BaseBoolField.