Enums and selection lists in XAML

Viewed 14

I've been at this all day and could now use some help. Thank you in advance.

Enums cannot be declared as partial; classes can. I had the need to combine multiple enum lists (which have assigned integers that are unique across enum groups) in a single list that is selectable in XAML using an attached property. I have looked a numerous things and I am still lost.

First, let's say I have the following code:

public enum Items {One, Two, Three};

public class DepObj : DependencyObject
{
      public static readonly DependencyProperty
         Field = DependencyProperty.RegisterAttached("Field", typeof(Items), typeof(DepObj), new PropertyMetadata(Items.One, OnFieldChanged));

      public static Items GetField(DependencyObject d)
      {
         return (Items)d.GetValue(Field);
      }

      public static void SetField(DependencyObject d, Items field)
      {
         d.SetValue(Field, field);
      }

      private static void OnFieldChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
         SetField(d, (Items)e.NewValue);
      }
}

Now, in XAML, I can set an Items property to "One" for instance. In XAML, I get a droplist of items that may be selected (One, Two, Three). Is there something special built into the XAML editor for enums that knows how to display this list? Or, is there something I can specify on any class that XAML would call within the class to provide this selection list?

I have looked at System.Enum (Microsoft System.Enum) and what it inherits from and I don't see what I need to do to provide equivalent functionality for my own class (or even a struct, if value types are required).

So my question is twofold:

  1. How does XAML provide selection lists for enums
  2. Is this functionality available to embed/use in classes that XAML will recognize

Thank you in advance.

0 Answers
Related