Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug ComboBox binding bug...
1 replies. Latest Post by StefanWick on December 28, 2008.
(0)
Alex Aza
Member
2 points
7 Posts
12-28-2008 8:45 AM |
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
Contributor
2864 points
438 Posts
12-28-2008 12:46 PM |
Thanks for the report Alex! I was able to replicate this.
I'll make sure this is on our bug list.
Thanks, Stefan Wick