none
Cannot change state after starting a storyboard programatically

    Question

  • Hi, I can't change states after I've manually created and started a storyboard. Even if the storyboard completes successfully, attempting to change state afterwards causes the following error at this line:

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

     ArgumentException: Value does not fall within the expected range.

     I know it's nothing to do with the animations within the storyboard, because I've commented them out (just ran an empty storyboard). This is a really bizarre problem. If I don't press my play button (to start the storyboard) I can change states just fine. But as soon as I press the button and the storyboard starts then I can never change states again.

     Thanks,

    Mark

    Tuesday, July 22, 2008 6:21 AM

Answers

  • OK. I see. This looks similar to a known issue: "ArgumentException when states & transitions animate both Visibility and Opacity properties". If I comment the ObjectAnimation for Visibility, it seems to work fine. This appears to be an animation bug caused by trying to set Visibility to a value null. It doesn't repro in all cases though. We're still investigating the reason. As a workaround, can you animate Opacity only?

    Monday, July 28, 2008 12:04 AM

All replies

  •  The blank storyboard is creating this problem. Remove the storyboard and try...

    Tuesday, July 22, 2008 7:33 AM
  •  No, the storyboard normally does have animations inside it, but it caused a crash, so I removed the animations and tried with an empty storyboard. Same problem.

    Tuesday, July 22, 2008 8:28 AM
  •  Can you copy paste the xaml, so that we can diagnose the problem

    Tuesday, July 22, 2008 8:31 AM
  • There is no XAML, it's all done in code.

    This is essentially what I'm doing:

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

    this.Storyboard = new Storyboard();
    this.Storyboard.Begin();

    VisualStateManager.GoToState(this, "State2", true); // CRASH!

    The actual code is spread over several classes and functions and is pretty difficult to separate. But, that code is what happens in order when clicking on the button.

    Mark

    Tuesday, July 22, 2008 8:43 AM
  •  Is the storyboard code also in code?

    Tuesday, July 22, 2008 8:47 AM
  •  Yes, but it doesn't matter if the storyboard has children or not. It crashes anyway (hence why I haven't included the animation code).

    Tuesday, July 22, 2008 8:51 AM
  • Hello, I can't reproduce this problem. Can you share a project?

    Thursday, July 24, 2008 3:29 AM
  •  Hi, yes I can do, can I email it to you? I also have the .XAP file hosted on the internet for you to test with.

    Thanks,

    Mark

    Thursday, July 24, 2008 4:06 AM
  • Hi, you can send an email to v-ylluo at microsoft.com.

    Thursday, July 24, 2008 4:48 AM
  •  Hi, I tried emailing but I get the following error:

    550 Sorry, <..myemail..> is not allowed access from your location

    Here is the contents anyway:
     

    I’ve managed to narrow down the problem to one specific XAML tag (highlighted in bold – if I comment out that code, it works just fine when I switch states):
     

    Note that the code is identical to the visual state “ViewModeTiled” (and yet switching between ViewModeTiled & ViewModeSingleImage works without any problems).
     

    <UserControl x:Class="DeepZoomViewer.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
          d:DesignWidth="512" d:DesignHeight="512">
          <UserControl.Resources>
          </UserControl.Resources>

          <Grid x:Name="LayoutRoot">
                <vsm:VisualStateManager.VisualStateGroups>
                      <vsm:VisualStateGroup x:Name="ViewModeStates">
                            <vsm:VisualStateGroup.Transitions>
                                  <vsm:VisualTransition Duration="00:00:00.2000000"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeSingleImage" To="ViewModeTiled"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeTiled" To="ViewModeSingleImage"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeSlideShow" To="ViewModeSingleImage"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeSlideShow" To="ViewModeTiled"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeTiled" To="ViewModeSlideShow"/>
                                  <vsm:VisualTransition Duration="00:00:00.2000000" From="ViewModeSingleImage" To="ViewModeSlideShow"/>
                            </vsm:VisualStateGroup.Transitions>
                            <vsm:VisualState x:Name="ViewModeSingleImage">
                                  <Storyboard Completed="Storyboard_Completed"/>
                            </vsm:VisualState>
                            <vsm:VisualState x:Name="ViewModeTiled">
                                  <Storyboard Completed="Storyboard_Completed">
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="thumbnailsContainer" Storyboard.TargetProperty="(UIElement.Opacity)">
                                              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="thumbnailsContainer" Storyboard.TargetProperty="(UIElement.Visibility)">
                                              <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                          <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                              </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                  </Storyboard>
                            </vsm:VisualState>
                            <vsm:VisualState x:Name="ViewModeSlideShow">
                                  <Storyboard Completed="Storyboard_Completed">
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="thumbnailsContainer" Storyboard.TargetProperty="(UIElement.Opacity)">
                                              <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="thumbnailsContainer" Storyboard.TargetProperty="(UIElement.Visibility)">
                                              <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                          <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                              </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>

                                  </Storyboard>
                            </vsm:VisualState>
                      </vsm:VisualStateGroup>
                </vsm:VisualStateManager.VisualStateGroups>
                <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto"/>
                      <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                      <RowDefinition Height="*"/>
                      <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid Visibility="Visible" x:Name="thumbnailsContainer" Width="100"/>
                <Border Grid.Column="1">
                </Border>
          </Grid>
    </UserControl>
     

    Thanks,

    Mark

    Thursday, July 24, 2008 6:14 AM
  • Hi, I tried your XAML with some code like this:

    private bool b;
    private Storyboard Storyboard;

     

    private void Storyboard_Completed(object sender, EventArgs e)
    {
    this.Storyboard = new Storyboard();
    this.Storyboard.Begin();
    }

    private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
    if (!b)
    {
    VisualStateManager.GoToState(this, "ViewModeSlideShow", true);
    }
    else
    {
    VisualStateManager.GoToState(this, "ViewModeSingleImage", true);
    }
    b = !b;
    }

     

    It works fine. I clicked the border a lot of times, and the state changes every time. If your problem still exists, can you upload the project to Sky Drive? Thanks.

     

    Friday, July 25, 2008 5:03 AM
  •  Hi, I've uploaded it to here:

    https://cid-f9c9bfe451e403e4.skydrive.live.com/self.aspx/Deep%20Zoom%20Viewer/DeepZoomViewer.zip

    I've added your MS email address to the list of people who can see the file. I have also added contact options to the comment of the file.

    The issue comes when going from the slideshow button to either of the tiled or single image buttons (on bottom right hand corner)

    Thanks,

    Mark

    Friday, July 25, 2008 6:12 AM
  • OK. I see. This looks similar to a known issue: "ArgumentException when states & transitions animate both Visibility and Opacity properties". If I comment the ObjectAnimation for Visibility, it seems to work fine. This appears to be an animation bug caused by trying to set Visibility to a value null. It doesn't repro in all cases though. We're still investigating the reason. As a workaround, can you animate Opacity only?

    Monday, July 28, 2008 12:04 AM
  •  Thanks for taking the time to investigate, much appreciated.

    I need the control to actually collapse so I guess I'll have to animate the opacity + width values. That should provide a suitable work around I imagine.

    Thanks,

    Mark

    Monday, July 28, 2008 3:42 AM