/// <summary> /// Populates the items source. /// </summary> private void PopulateItemsSource() { // We must have an items source and an item which is an enum. if (ItemsSource != null || SelectedEnumeration is Enum == false) { return; } // Get the enum type. var enumType = SelectedEnumeration.GetType(); // Get the enum values. Use the helper rather than Enum.GetValues // as it works in Silverlight too. var enumValues = Apex.Helpers.EnumHelper.GetValues(enumType); // Create some enum value/descriptions. Enumerations = new List <NameValue>(); // Go through each one. foreach (var enumValue in enumValues) { // Add the enumeration item. Enumerations.Add(new NameValue(((Enum)enumValue).GetDescription(), enumValue)); } // Set the items source. ItemsSource = Enumerations; // Initialise the control. Initialise(); }
/// <summary> /// Initialises this instance. /// </summary> private void Initialise() { // Set the display member path and selected value path. DisplayMemberPath = "Name"; #if !WINDOWS_PHONE SelectedValuePath = "Value"; #endif // If we have enumerations and a selected enumeration, set the selected item. if (Enumerations != null && SelectedEnumeration != null) { var selectedEnum = from enumeration in Enumerations where enumeration.Value.ToString() == SelectedEnumeration.ToString() select enumeration; this.SelectedItem = selectedEnum.FirstOrDefault(); } // Wait for selection changed events. SelectionChanged += new SelectionChangedEventHandler(EnumerationComboBoxTemp_SelectionChanged); }