Ok this has been bugging me and I haven't really found any kind of definitive answer as the the reason/cause of the difference between Color
& SolidColorBrush
so I'm wondering if someone can educate me on this.
I already know the differences in usage, like for example I can use a SolidColorBrush
in a dependency like if I say;
<SolidColorBrush x:Key="BlahBrush" Color="#FFFFFFFF"/>
<Border Background="{StaticResource BlahBrush}"/>
but then say I throw the same resource in an EasingColorKeyFrame
kind of like;
<EasingColorKeyFrame KeyTime="0" Value="{StaticResource BlahBrush}" />
then it's going to puke at me about it being a SolidColorBrush....except then I can get around that by just declaring it via a resource chain back to a Color
kind of like;
<Color x:Key="OriginalBlahBrush">#FFFFFFFF</Color>
<SolidColorBrush x:Key="BlahBrush" Color="{StaticResource OriginalBlahBrush}"/>
and it will be just fine....but then again I could just utilize the Color
property alone of the SolidColorBrush
and can get the same behavior without being separated kind of like;
<SolidColorBrush>
<SolidColorBrush.Color>
<Color A="255" R="0" G="0" B="255" />
</SolidColorBrush.Color>
</SolidColorBrush>
So I guess my question is, what is the inherent difference between the Colors and SolidColorBrush class's and the reason for their weird quirks in usage? aka I guess what's the reason for System.Windows.Media.Colors vs System.Windows.Media.SolidColorBrush if they're both just giving a solid damn color??
Inquiring minds want to know! :)
The most common way to use SolidColorBrush is to define a XAML element as a resource in a ResourceDictionary, and then reference that resource later from other parts of UI definitions, styles or templates using either {StaticResource} markup extension or {ThemeResource} markup extension s.
Solid Brush in WPFA solid brush is the most basic brush and paints an area with a solid color. The SolidColorBrush object represents a solid color brush. The Opacity property of the SolidColorBrush represents the transparency of the color that values between 0 and 1 where 0 is fully transparent and 1 is fully opaque.
From the Remarks section in Brush:
A Brush "paints" or "fills" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color, others with a gradient, pattern, image, or drawing. The following list describes the different types of WPF brushes:
•SolidColorBrush: Paints an area with a solid Color.
•LinearGradientBrush: Paints an area with a linear gradient.
•RadialGradientBrush: Paints an area with a radial gradient.
•ImageBrush: Paints an area with an image (represented by an ImageSource object).
•DrawingBrush: Paints an area with a Drawing. The drawing may include vector and bitmap objects.
•VisualBrush: Paints an area with a Visual object. A VisualBrush enables you to duplicate content from one portion of your application into another area; it's very useful for creating reflection effects and magnifying portions of the screen.
Color
is a component of SolidColorBrush
and one of it constructor has Color-type parametr. If you want to fill some components on the forms first you need to create color and after create SolidColorBrush
based on that color which you was created earlier. It's like a real clear brush and color palette, where you need to soak the brush for painting/filling something.
Color
object is more "low-level" and you can set some color with A, R, G, B-parameters.
And SolidColorBrushes
is a type of brushes for filling object (inheritance from System.Windows.Media.Brush). You can combine colors in one Brush.
My understanding is the following.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With