views:

177

answers:

2

Hi, I'm trying to activate a state when the screen is loaded but it doesn't work. What I do is, I go to the screen, right click the LayoutRoot and then go "Activate State" and I pick my state. Then when I click on this newly generated [ActivateStateAction] I change the EventName from MouseLeftButtonDown to Loaded. However, it doesn't seem to work. The MouseLeftButtonDown works but not the Loaded. I tried this on multiple screens (not just the startup screen) but it still doesn't work, any ideas?

+1  A: 

I repeated the steps you gave and it worked for me. You didn't mention SL or WPF, so I tried it in Silverlight. Maybe check the properties of the activatestateaction to be sure the target state name is correct. Let me know if you still can't get it working and I can try to help find the problem (post your xaml). Here is the xaml generated by my actions:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:pb="clr-namespace:Microsoft.Expression.Prototyping.Behavior;assembly=Microsoft.Expression.Prototyping.Interactivity"
x:Class="SilverlightPrototype2Screens.Screen_1"
Width="640" Height="480">

<Grid x:Name="LayoutRoot" Background="White">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <pb:ActivateStateAction TargetScreen="SilverlightPrototype2Screens.Screen_1" TargetState="VisualState"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateGroup">
            <VisualState x:Name="VisualState">
                <Storyboard>
                    <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                        <EasingColorKeyFrame KeyTime="00:00:00" Value="Red"/>
                    </ColorAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Rectangle x:Name="rectangle" Fill="White" Stroke="Black" Height="74" HorizontalAlignment="Left" Margin="171,116,0,0" VerticalAlignment="Top" Width="107" RenderTransformOrigin="0.5,0.5">
        <Rectangle.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Rectangle.RenderTransform>
    </Rectangle>
</Grid>

Chuck Hays
okay i'll try it out later when i get home. i've been doing animation on loads instead for the meantime, those seem to have been working better for me for some reason. btw, excellent product. it's been my favorite new toy. and yes, i use the silverlight sketchflow project.
Shnitzel
A: 

I had the same problem.

I found out the ActivateStateAction Loaded, was only called for my first screen. Similar actions on other screens which I then navigated to weren't calling the Loaded event.

I changed my ActivateStateAction to use to Layout Updated action on all screen but the first. This event is fired when a new screen updates the layout and now my problem is fixed.

bleakcabal