Question

In a ResourceDictionary I defined a Color:

<Color x:Key="DefaultButtonBrush">Green</Color>

This color I'm using in the same ResourceDictionary for a ColorAnimation:

<ColorAnimation Storyboard.TargetName="ButtonRectangle" 
    Storyboard.TargetProperty="(Rectangle.Stroke).(SolidColorBrush.Color)"
    To="{StaticResource DefaultButtonBrush}" Duration="{StaticResource HalfSecond}"/>

This just works fine.

Now I want to use the same Color for the Stroke of a Rectangle. There I get the error:

A object of the type "System.Windows.Media.Color" cannot be applied to a property that expects the type "System.Windows.Media.Brush"

I understand the errormessage, but I don't want to create a separat Resource for the Brush. Is there a possibility to use the Color also for the Stroke of my Rectangle?

Was it helpful?

Solution

Stroke is of type Brush.You must create Brush from Color to assign to Brush.

<Rectangle>
  <Rectangle.Stroke>
    <SolidColorBrush Color="{StaticResource DefaultButtonBrush}"/>
  </Rectangle.Stroke>
</Rectangle>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top