wpf – Color和SolidColorBrush澄清之间的区别

好的,这一直困扰着我,我还没有真正找到任何确定的答案,因为Color&之间差异的原因/原因. SolidColorBrush所以我想知道是否有人可以教我这个.

我已经知道使用上的差异,例如我可以在依赖中使用SolidColorBrush,就像我说的那样;

<SolidColorBrush x:Key="BlahBrush" Color="#FFFFFFFF"/>
<Border Background="{StaticResource BlahBrush}"/>

但后来说我在EasingColorKeyFrame中抛出相同的资源;

<EasingColorKeyFrame KeyTime="0" Value="{StaticResource BlahBrush}" />

那么它会让我觉得它是一个SolidColorBrush ….除此之后我可以解决这个问题,只需通过资源链将其声明为颜色类似于;

<Color x:Key="OriginalBlahBrush">#FFFFFFFF</Color>
<SolidColorBrush x:Key="BlahBrush" Color="{StaticResource OriginalBlahBrush}"/>

它会很好……但是我再一次只能使用SolidColorBrush的Color属性并且可以获得相同的行为而不会被分开.

<SolidColorBrush>
     <SolidColorBrush.Color>
        <Color A="255" R="0" G="0" B="255" />
     </SolidColorBrush.Color>
</SolidColorBrush>

所以我想我的问题是,Colors和SolidColorBrush类之间的固有区别是什么,以及它们使用中奇怪的怪癖的原因是什么?我猜想System.Windows.Media.Colors与System.Windows.Media.SolidColorBrush的原因是什么,如果它们都只是给出了一个坚实的颜色?

询问心灵想知道! 🙂

最佳答案 从
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.

点赞