Jacek Wojcik
Jacek Wojcik

Reputation: 1253

VisualState, StoryBoard, Instant change of color (without animation)

my task seemed to me as something easy (WinRT).

All I want is to change color of Rectangle depending on state.

I know how to do it in a "cool" animated way.

The thing is that I just want my color to be changed immediately without any animation.

This is a standard, cool way:

<VisualState x:Name="UnFocused">
    <Storyboard Duration="1">
        <ColorAnimation To="{ThemeResource LightGrayColor}"   
            Storyboard.TargetName="borderBrush"  
            Storyboard.TargetProperty="Color"/>
    </Storyboard>
</VisualState>  

I thought that if I change Duration to zero then the change will be instant.

It does not work this way, color did not change at all.

So I tried "0:0:0.1" but it did not change color either.

So...

What is the current approach to change color in instant using VisualState functionality?

Thank you :-)

Upvotes: 0

Views: 1297

Answers (2)

Mark
Mark

Reputation: 6947

Turning @Jacek-Wojcik's comment into an answer:

Don't set a duration on the storyboard, set it on the ColorAnimation instead:

<VisualState x:Name="UnFocused">
  <Storyboard >
    <ColorAnimation Duration="0" To="{ThemeResource LightGrayColor}"   
        Storyboard.TargetName="borderBrush"  
        Storyboard.TargetProperty="Color"/>
 </Storyboard>
</VisualState>  

Upvotes: 0

gomi42
gomi42

Reputation: 2519

I don't know whether WinRT has some restrictions. At least I would also have expected that zero works fine. But you have some more options and still being cool:

<ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                Storyboard.TargetName="borderBrush"
                                Storyboard.TargetProperty="Color">
    <DiscreteObjectKeyFrame KeyTime="00:00:00">
        <DiscreteObjectKeyFrame.Value>
            <SolidColorBrush Color="{ThemeResource LightGrayColor}"/>
        </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>

or

<ColorAnimationUsingKeyFrames Storyboard.TargetName="borderBrush"
                              Storyboard.TargetProperty="Color">
    <EasingColorKeyFrame KeyTime="0" 
                         Value="{ThemeResource LightGrayColor}" />
</ColorAnimationUsingKeyFrames>

Upvotes: 1

Related Questions