Marcelo de Aguiar
Marcelo de Aguiar

Reputation: 1442

VisualStateManager.GoToSate() does not work

I am trying to create visual states in my WP8 app. But I can't get it to work, even this simple example. Can anybody spot what is wrong?

<StackPanel x:Name="LayoutRoot" Background="Transparent" Margin="1,0,-1,0">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="Faded">
                <Storyboard>
                    <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ToFade" d:IsOptimized="True"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Button Content="some text" x:Name="ToFade" />
    <Button Content="Change"
            Click="Button_Click" />
</StackPanel>

In code behind:

    private void Button_Click( object sender, RoutedEventArgs e ) {
        var result = VisualStateManager.GoToState(this.ToFade, "Faded", true);
    }

It is supposed to animate opacity of the top button.

Upvotes: 0

Views: 174

Answers (1)

anderZubi
anderZubi

Reputation: 6424

I think the first parameter of GoToState() method should be the page itself. Try by calling GoToState() as follows:

VisualStateManager.GoToState(this, "Faded", true);

Upvotes: 2

Related Questions