AsValeO
AsValeO

Reputation: 3039

XAML TextBlock animate BackGround if new value exceeds previous

TextBox is binded to property of type int in ViewModel. Its value continuously changes and notifies View. I want to animate its Background. If the new value exceeds the previous value, set Background to green for 1 sec, if not, set red.

How can I do it?

UPDATE: This is the closest thing for now. But color is always the same regardless the new value exceeds the previous one or not.

<Style x:Key="SuperStyle" TargetType="{x:Type TextBlock}">
    <Style.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)">
                    <Storyboard>
                        <ColorAnimation From="Transparent" To="LightGreen" Duration="0:0:1" />
                        <ColorAnimation From="LightGreen" To="Transparent" Duration="0:0:2" />
                    </Storyboard>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Style.Triggers>
</Style>

Upvotes: 0

Views: 58

Answers (1)

Vadi
Vadi

Reputation: 57

You can use converters ,Bind Textbox background to your value and pass it to concerter which returns color brush to your textbox

See link

WPF converter to update in real time background colour of textbox on text change

Upvotes: 1

Related Questions