2

Using OxyPlot, I want to provide the user of my WPF Application with a combobox containing all available OxyColors to select one color.

From the sourcecode, one can see that the OxyColors are public static readonlyproperties of the static OxyColors class.

The Question is, if there is a way to bind all colors as itemsource of a combobox. The only thing I can think of so far is to create a List<OxyColor> and manually add all of the colors to it, but maybe there is a more elegant way to tackle this problem.

Edit: Found this answer to a similar problem. However, again it is manually creating a List of all colors.

Roland Deschain
  • 2,211
  • 19
  • 50
  • 1
    There is no "more elegant" way than, one way or another, adding all colours to an `IEnumerable` that you bind to the `ComboBox`. – mm8 Feb 28 '19 at 16:29
  • 1
    You just need to create a custom list ONCE, have it in a XAML resource dictionary, and [re-use it everywhere you want](https://imgur.com/IBYeb0n), FOREVER...:O) – jsanalytics Feb 28 '19 at 23:10
  • @jsanalytics thanks for the input. ATM I solved it via reflection within the viewmodel. However since there are several viewmodels for the same usercontrol within my project, this function runs several times (10-20ms each). I will look into a good way to put the list into the apps resource dictionary on startup and only have to run it once. – Roland Deschain Mar 01 '19 at 10:51
  • Either you have a solution or you don't.... If you do, then you should post it and mark your question as answered. – jsanalytics Mar 01 '19 at 20:57

0 Answers0