alex loffler
alex loffler

Reputation: 3

How to create a property of type System.Windows.Media.Color with a custom value

I'm creating a ViewModel and I can't find a way to create something like the following pseudo code:

 private Color _GradientColor = new Color().DodgerBlue;  //Something like this

I can do:

private SolidColorBrush _GradientColor = new SolidColorBrush(Colors.DodgerBlue);

But it is not what i need.

Upvotes: -1

Views: 766

Answers (1)

Christopher
Christopher

Reputation: 9814

Those two are not remotely equivalent.

private Color _GradientColor;
_GradientColor = new Color().DodgerBlue;  //Something like this

You are creating a instance of Color, to then access a property that contains a instance for DodgerBlue?

private SolidColorBrush _GradientColor = new SolidColorBrush(Colors.DodgerBlue);

Here you create a instance of SolidColorBrush, giving it a Constant, Static, or Enumeration value as input. As it is Colors (plural) it is extremely likely a Enumeration - a thing you can not instantiate. If it is a Enumeration, this might be the code you are looking for:

private Color _GradientColor;
_GradientColor = Colors.DodgerBlue;

However, that might be the wrong track overall. As a general, the ViewModel does not deal with Colors. That is a unambigious, View side thing. You may be looking for a converter? Or maybe you have a special ViewModel just for stuff like Colors?

Upvotes: 0

Related Questions