Ejemplo n.º 1
0
        /// <summary>
        /// PopulateDropDown
        /// </summary>
        private void PopulateDropDown(ComboBox comboBox)
        {
            try
            {
                Type t = typeof(System.Windows.Media.Colors);
                comboBox.Items.Clear();

                foreach (PropertyInfo p1 in t.GetProperties())
                {

                    System.Windows.Media.ColorConverter d = new System.Windows.Media.ColorConverter();

                    try
                    {

                        ComboBoxItem item = new ComboBoxItem();

                        SolidColorBrush brush = new SolidColorBrush((System.Windows.Media.Color)d.ConvertFromInvariantString(p1.Name));
                        item.Background = brush;
                        item.Content = p1.Name;

                        if (brush.Color == Colors.Black || brush.Color == Colors.White)
                            comboBox.Items.Add(item);
                    }
                    catch
                    {
                        // Catch exceptions here
                    }
                }
                comboBox.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }