How to associate with color in WPF ColorAnimation?

I would like to do something that seems pretty simple, but I cannot figure out how to do it. I have a ColorAnimation that fires when the MouseEnter event occurs. It just changes the background color of the border from one color to another.

Unfortunately, I cannot figure out how to put in ColorAnimation anything but hard-coded colors. It currently looks like this:

<Style x:Key="MouseOverStyle">
<Style.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation Duration="0:0:0.5" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                                    To="Red" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>
</Style.Triggers>
</Style>

However, I would like to do something like this:

<SolidColorBrush x:Key="MyEventColor" Color="{Binding EventColor}" />

<Style x:Key="MouseOverStyle">
<Style.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation Duration="0:0:0.5" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                                    To="{StaticResource MyEventColor}" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>
</Style.Triggers>
</Style>

Or like this:

<Style x:Key="MouseOverStyle">
<Style.Triggers>
    <EventTrigger RoutedEvent="Mouse.MouseEnter">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation Duration="0:0:0.5" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                                    To="{Binding EventColor}" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>
</Style.Triggers>
</Style>

, . -, , , "" SolidColorBrush... ... , , , ColorAnimation "(Border.Background). (SolidColorBrush)"... "(Border.Background). (SolidColorBrush.Color)".

, " "... , ColorAnimation - , ? ... .

​​ ?

+5
1

{StaticResource MyColor} MyColor, :

<Color x:Key="MyColor">#FF00FF00</Color>

: , () . , , .

+7

All Articles