tags:

views:

85

answers:

1

Hello. I have next enumeration

Enum rcCategory
{
  Incoming,
  Internal,
  Outgoing
}

and I have property "categories" in my class which has rcCategory[] type.

I would like to bind this property to the listBox. I use next code for this

MyListBox.SetBinding (ListBox.ItemsSource, new Binding {Source= myClass.categories});

But this code doesnt work as expected. How Can I do this. My listBox always is empty but source property has value

+1  A: 

See Bea Stollnitz top ranked article on it.
In short you need to bind to an ObjectProvider which calls the static method Enum.GetValues( typeof(YourEnum) ) to return the list.

http://bea.stollnitz.com/blog/?p=28

Update: Sorry got a slight speedreading issue. This one is easier.. Verified that it works. Recommended: Find up a copy of ProgrammingWPF and go thru the DataBinding chapter...

XAML:

<ListBox DockPanel.Dock="Left" ItemsSource="{Binding EnumArrayProp}"/>

Codebehind:

public partial class Window1 : Window
   {
       public rcCategory[] EnumArrayProp
       {
           get; set;
       }
       public Window1()
       {
           InitializeComponent();

           this.EnumArrayProp = new rcCategory[] { rcCategory.Incoming, rcCategory.Incoming, rcCategory.Outgoing };

           this.DataContext = this;

       }
Gishu
I read this article. But in this only example of binding simple enum to ListBox. My problem with enum[] not simple enum
Polaris
@Polaris - sorry. updated answer.
Gishu
It's works. thank you
Polaris