wpfcomboboxcolorssystemcolors

Loading a combo box with all system colors in wpf


I have created combo box that I would like to load with all of the standard colors. I would like to do this in the xaml.cs file rather than the straight XAML. I have found many examples to do this in the C# for .NET but not WPF.

I found the following code that runs in .NET and it seems that prop.PropertyType.FullName never equals "System.Drawing.Color") I debugged through it and the only value that System.Reflection.PropertyInfo eqauls that makes sense is System.Windows.Media.ColorContext. But when i tried this it did not return any colors.

foreach (System.Reflection.PropertyInfo prop in typeof(Color).GetProperties())
{
if (prop.PropertyType.FullName == "System.Drawing.Color")
comboBox1.Items.Add(prop.Name);
}

Any Suggestions or comments are appreciated.

Thanks!


Solution

  • This worked for me. Try a Debug. You may be getting the colors but the problem is with is add items.

            foreach (System.Reflection.PropertyInfo info in typeof(Colors).GetProperties())
            {
                Debug.WriteLine(info.Name);
    
            }