0

I have a one question. I use OxyPlot in WPF, C#. I need to have all colors to MarkerType and MarkerStroke for series. How I can get all colors?

Mario
  • 9
  • 3
  • 1
    put your code what you have tried.. – Farman Ud Din May 30 '18 at 10:20
  • public List koloryWykresow=new List { OxyPlot.OxyColors.Green, OxyPlot.OxyColors.IndianRed, OxyPlot.OxyColors.Coral, OxyPlot.OxyColors.Chartreuse, OxyPlot.OxyColors.Peru }; I must change this code lists have only some elements. I can write many colors but this isnt smart solution – Mario May 30 '18 at 10:45
  • @Mario, can you please give any feedback to my answer? – ASh Jun 28 '18 at 11:31

1 Answers1

1

Green, IndianRed, etc are static fields in static OxyColors class. use to read all of them

var colors = typeof(OxyColors)
             .GetFields(BindingFlags.Static | BindingFlags.Public)
             .Where(f => f.FieldType == typeof(OxyColor))
             .Select(f => f.GetValue(null))
             .Cast<OxyColor>()
             .ToList();
ASh
  • 34,632
  • 9
  • 60
  • 82
  • Having a similar problem I tested this out and it is working fine. [However I am wondering if there is a more elegant solution to this](https://stackoverflow.com/questions/54906806/oxyplot-how-to-bind-all-oxycolors-as-itemsource-of-a-wpf-combobox) (I don't like the idea of creating yet another list of all the colors, when we already have all the information saved in the `OxyColors` class.) – Roland Deschain Feb 27 '19 at 14:21
  • OxyColors doesn't contain a list. But you can create your own and store it in a `static` property in any relevant class – ASh Feb 27 '19 at 16:47