Skip to main content

Microsoft Silverlight

Answered Question ComboBox binding bug...RSS Feed

(0)

Alex Aza
Alex Aza

Member

Member

2 points

7 Posts

ComboBox binding bug...

ComboBox doesn't call ToString() on enumeration types.

XAML:

 <StackPanel>
    <ListBox x:Name="listBox" />
    <ComboBox x:Name="comboBox" />
</StackPanel>

C#

 

1        public partial class Page : UserControl
2        {
3            public static T[] GetEnumValues<T>()
4            {
5                var type = typeof(T);
6                if (!type.IsEnum)
7                    throw new ArgumentException("Type '" + type.Name + "' is not an enum");
8    
9                return (
10                   from field in type.GetFields()
11                   where field.IsLiteral
12                   select (T)field.GetValue(type)).ToArray();
13           }
14   
15           public Page()
16           {
17               InitializeComponent();
18               var enums = GetEnumValues<TestEnum>();
19               listBox.ItemsSource = enums;
20               comboBox.ItemsSource = enums;
21           }
22       }
23   
24       public enum TestEnum
25       {
26           test1,
27           test2,
28           test3
29       }
The listBox and comboBox are set to the same data source, which is the array of enumeration values.
The listBox shows string values of enumeration (test1, test2 and test3), while the comboBox shows int values (0, 1 and 2).
 

StefanWick
StefanWick

Contributor

Contributor

2864 points

438 Posts

Microsoft
Answered Question

Re: ComboBox binding bug...

Thanks for the report Alex! I was able to replicate this.

I'll make sure this is on our bug list.

Thanks, Stefan Wick

Microsoft Silverlight | http://blogs.msdn.com/swick/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities