Page view counter
ComboBox binding bug... Subscribe to this thread
Last post 12-28-2008 12:46 PM by StefanWick. 1 replies.
Sort Posts:
12-28-2008 8:45 AM
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).
 
Alex Aza

Loading...
Joined on 12-28-2008
Posts 7
12-28-2008 12:46 PM
Marked as Answer
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/

StefanWick

Loading...
Joined on 06-15-2007
Microsoft
Posts 405
Microsoft Communities