0

I'm changing the TextBlock color through the trigger, after 5 seconds, I would like to switch the color back to the TextBlock's initial, default color that is defined in the resource dictionary, without defining the color explicitly.

Here is the TextBlock style I use:

<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="{x:Type TextBlock}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsSelected}" Value="True">
            <Setter Property="Foreground" Value="{StaticResource LightBackgroundBrush}" />

            <!--  Go back to initial color  -->
            <DataTrigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation
                            BeginTime="0:0:05"
                            Storyboard.TargetProperty="Foreground.Color"
                            To="???" />
                    </Storyboard>
                </BeginStoryboard>
            </DataTrigger.EnterActions>
        </DataTrigger>
    </Style.Triggers>
</Style>

I mean this line specifically:

<ColorAnimation
   BeginTime="0:0:05"
   Storyboard.TargetProperty="Foreground.Color"
   To="???" />

I have tried setting To property to {x:Null} markup extension, however the color remains the same.

How can I make it animate to the default color?


edit

Since @Rekshino marked this question as a possible duplicate, I want to state that there is no relation between my question and the question linked by him, hence question might have been misunderstood by him as I haven't asked about To property bindings.

Community
  • 1
  • 1
RA.
  • 969
  • 13
  • 36
  • Possible duplicate of [WPF animation: binding to the "To" attribute of storyboard animation](https://stackoverflow.com/questions/2186933/wpf-animation-binding-to-the-to-attribute-of-storyboard-animation) – Rekshino Jun 06 '19 at 12:22
  • See also the answer to the [WPF Animation “Cannot freeze this Storyboard timeline tree for use across threads”](https://stackoverflow.com/questions/1669750/wpf-animation-cannot-freeze-this-storyboard-timeline-tree-for-use-across-thread) – Rekshino Jun 06 '19 at 12:23
  • @Rekshino Sorry, I don't see how these questions relate to my problem. I haven't said a word about bindings. – RA. Jun 06 '19 at 12:36
  • Actually, that you need is to use `To="{Binding Foreground, RelativeSource={RelativeSource AncestorType=TextBlock}}"`, but you can't do it in a style, only in control's triggers. – Rekshino Jun 06 '19 at 12:49

0 Answers0