How to apply a VisualTransition programatically RRS feed

  • Question

  • I have a need to dynamically apply a single  VisualState by changing the TargetName of the Storyboard at runtime.

    So I moved the Storyboard as a resource with a key name.

    		<Storyboard x:Key="ShowScreen_Storyboard">
    			<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)"/>

    Within my Visual State I refer to the story board.

    	<VisualStateGroup x:Name="VisualStateGroup">
    			<VisualTransition GeneratedDuration="0:0:02" To="ShowScreen">
    		<VisualState x:Name="ShowScreen" Storyboard="{StaticResource ShowScreen_Storyboard}"/>

    So within the code behind I can set the Storyboard TargetName with a passed string.  And I can execute the state.  But the visualtransition doesn't get applied?

    Dim sb as Storyboard = DirectCast(Resources("ShowScreen_Storyboard"),Storyboard) sb.SetValue(Storyboard.TargetNameProperty,ScreenName) sb.Begin(LayoutRoot)

    How would I execute the defined Transition for the Storyboard of the State within code?

    Jeff Davis

    Tuesday, July 30, 2013 5:49 PM


  • I gave up on figuring this out.

    I got rid of the VisualStateGroups altogether  and just created my own slidin transition withing the Storyboard defined in the Resource

    <Storyboard x:Key="ShowScreen_Storyboard"> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)"/>

    <ThicknessAnimation Duration="0:0:1" Storyboard.TargetProperty="Margin" From="-1400,0,0,0" To="0,0,0,0" AccelerationRatio=".5"/> </Storyboard> </Window.Resources>

    Jeff Davis

    • Marked as answer by JeffD503 Wednesday, July 31, 2013 7:27 PM
    Wednesday, July 31, 2013 7:27 PM