Reputation: 3863
What is the the differnce between solidcolorbrush and brush, In WPF (C#).
SolidColorBrush br = new SolidColorBrush(Colors.Red);
and
Brush br = Brushes.Red;
Upvotes: 4
Views: 8140
Reputation: 81253
To answer your question No difference.
Brushes.Red
returns SolidColorBrush
only. Its definition is like:
public static SolidColorBrush Red { get; }
You can assume its default template which Microsoft provides you for basic colors.
Use SolidColorBrush constructor in case you want to provide your own custom A,R,G,B values for color.
This will get you actual Red
color:
SolidColorBrush anotherBrush =
new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
This will get you Red color with G
component set to 100 byte
and B
component set to 50 byte
.
SolidColorBrush anotherBrush =
new SolidColorBrush(Color.FromArgb(255, 255, 100, 50));
Upvotes: 8
Reputation: 2529
Brush is the base class and holds any type of brush no matter how it was created. SolidColorBrush constructs a brush having a solid Color, LinearGradientBrush is another way to constract a brush and there are by far more. And WPF offers a huge set of predefined brushes in the Brushes class. They are of type SolidColorBrush just in order to say: a single, solid color.
Upvotes: 1
Reputation: 157098
None.
MSDN says:
public static SolidColorBrush Red { get; }
So in fact this is a static SolidColorBrush. With your first line of code you create a similar object.
Upvotes: 3