PDA

View Full Version : Calling different States On MouseMove



bouncer
September 12th, 2009, 04:27 PM
Hi,

I have a control which has 4 states defined something like this :


<Grid x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.4000000"/>
<VisualTransition From="AnimateUp" GeneratedDuration="00:00:00.4000000" To="Normal"/>
<VisualTransition From="AnimateDown" GeneratedDuration="00:00:00.4000000" To="Normal"/>
<VisualTransition From="AnimateRight" GeneratedDuration="00:00:00.4000000" To="Normal"/>
<VisualTransition From="AnimateLeft" GeneratedDuration="00:00:00.4000000" To="Normal"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="AnimateUp">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="grdProjection" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="-33"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AnimateDown">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="grdProjection" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="44"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AnimateRight">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="grdProjection" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="-33"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="AnimateLeft">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="grdProjection" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="33"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="grdProjection" Margin="45,35,50,52" MouseMove="grdProjection_MouseMove">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF5B5B5B" Offset="0"/>
<GradientStop Color="#FF8E8E8E" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>

</Grid>
</Grid>

Now I want to call different states on MouseMove. For example when mouse direction is up I want to call AnimateUp state, when direction is down it will call AnimateDown state , so on.

Somebody please help me by giving me some idea.

kirupa
September 12th, 2009, 08:16 PM
Hi bouncer,
I just wrote a tutorial on how to call custom states programmatically or via code here: http://www.kirupa.com/blend_silverlight/custom_vsm_pg1.htm (the last two pages will be most helpful for you).

Are you unsure how to call the states, or are you unsure how to detect the direction of mouse movement?

Thanks,
Kirupa

bouncer
September 23rd, 2009, 03:26 PM
Hi bouncer,
I just wrote a tutorial on how to call custom states programmatically or via code here: http://www.kirupa.com/blend_silverlight/custom_vsm_pg1.htm (the last two pages will be most helpful for you).

Are you unsure how to call the states, or are you unsure how to detect the direction of mouse movement?

Thanks,
Kirupa

I know how to call the states but not sure about the detection of mouse. I want to call each states on each direction.

Gazman
September 23rd, 2009, 04:22 PM
To determine mouse movement direction I think you will have to make some code.

Here is a C# example on how to accomplish this:

http://bytes.com/topic/c-sharp/answers/256606-determine-mouse-movement-direction

Perhaps call this code with a timer.