Add animations to controls
Visual Basic tutorials for UWP apps.
1 post
Page 1 of 1
Various Storyboard codes to add animations to XAML controls
I'm posting these here to share and so I don't lose them if my main system goes down lol
You can apply the animation to any control on the XAML page, example:
I'm posting these here to share and so I don't lose them if my main system goes down lol
You can apply the animation to any control on the XAML page, example:
Code: Select all
Need Import:
BounceAni(Button1)
Code: Select all
Bounce:
Imports Windows.UI.Xaml.Media.Animation
Code: Select all
Spin:
Public Sub BounceAni(sender As Object)
Dim da As DoubleAnimation = New DoubleAnimation()
da.Duration = New Duration(TimeSpan.FromMilliseconds(200))
da.From = 0
da.To = -20
da.RepeatBehavior = New RepeatBehavior("1")
da.AutoReverse = True
CType(sender, Button).Projection = New PlaneProjection
da.EnableDependentAnimation = True
Dim sb As Storyboard = New Storyboard()
Storyboard.SetTarget(da, CType(sender, Button).Projection)
Storyboard.SetTargetProperty(da, "GlobalOffsetY")
sb.Children.Add(da)
sb.Begin()
End Sub
Code: Select all
Zoom out and in:
Public Sub SpinAni(sender As Object)
CType(sender, Button).Visibility = Windows.UI.Xaml.Visibility.Visible
Dim Scalex As DoubleAnimation = New DoubleAnimation()
Scalex.Duration = New Duration(TimeSpan.FromMilliseconds(200))
Scalex.From = 0
Scalex.To = 360
'Scalex.AutoReverse = True
Scalex.RepeatBehavior = New RepeatBehavior("1")
CType(sender, Button).RenderTransform = New RotateTransform
Scalex.EnableDependentAnimation = True
Dim Popout As Storyboard = New Storyboard()
Storyboard.SetTarget(Scalex, CType(sender, Button).RenderTransform)
Storyboard.SetTargetProperty(Scalex, "Angle")
Popout.Children.Add(Scalex)
Popout.Begin()
End Sub
Code: Select all
Zoom in and out:
Public Sub ZoomOutAni(sender As Object)
Dim Scalex As DoubleAnimation = New DoubleAnimation()
Scalex.Duration = New Duration(TimeSpan.FromMilliseconds(300))
Scalex.From = 1
Scalex.To = 2
Scalex.AutoReverse = True
Scalex.RepeatBehavior = New RepeatBehavior("1")
CType(sender, Button).RenderTransform = New ScaleTransform
Scalex.EnableDependentAnimation = True
Dim ScaleY As DoubleAnimation = New DoubleAnimation()
ScaleY.Duration = New Duration(TimeSpan.FromMilliseconds(300))
ScaleY.From = 1
ScaleY.To = 2
ScaleY.AutoReverse = True
ScaleY.RepeatBehavior = New RepeatBehavior("1")
CType(sender, Button).RenderTransform = New ScaleTransform
ScaleY.EnableDependentAnimation = True
Dim Popout As Storyboard = New Storyboard()
Storyboard.SetTarget(Scalex, CType(sender, Button).RenderTransform)
Storyboard.SetTargetProperty(Scalex, "ScaleX")
Storyboard.SetTarget(ScaleY, CType(sender, Button).RenderTransform)
Storyboard.SetTargetProperty(ScaleY, "ScaleY")
Popout.Children.Add(Scalex)
Popout.Children.Add(ScaleY)
Popout.Begin()
End Sub
Code: Select all
Slide Down:
Public Sub ZoomInAni(ByVal sender As [Object])
Dim doubleAnimation As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
Dim duration As Windows.UI.Xaml.Duration = New Windows.UI.Xaml.Duration(TimeSpan.FromMilliseconds(300))
doubleAnimation.Duration = duration
doubleAnimation.From = 0
doubleAnimation.To = 1
doubleAnimation.AutoReverse = False
Dim repeatBehavior As Windows.UI.Xaml.Media.Animation.RepeatBehavior = New Windows.UI.Xaml.Media.Animation.RepeatBehavior("1")
doubleAnimation.RepeatBehavior = repeatBehavior
DirectCast(sender, Button).RenderTransform = New ScaleTransform()
doubleAnimation.EnableDependentAnimation = True
Dim doubleAnimation1 As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
duration = New Windows.UI.Xaml.Duration(TimeSpan.FromMilliseconds(300))
doubleAnimation1.Duration = duration
doubleAnimation1.From = 0
doubleAnimation1.To = 1
doubleAnimation1.AutoReverse = False
repeatBehavior = New Windows.UI.Xaml.Media.Animation.RepeatBehavior("1")
doubleAnimation1.RepeatBehavior = repeatBehavior
DirectCast(sender, Button).RenderTransform = New ScaleTransform()
doubleAnimation1.EnableDependentAnimation = True
Dim storyboard As Windows.UI.Xaml.Media.Animation.Storyboard = New Windows.UI.Xaml.Media.Animation.Storyboard()
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation, (DirectCast(sender, Button)).RenderTransform())
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation, "ScaleX")
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation1, (DirectCast(sender, Button)).RenderTransform())
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation1, "ScaleY")
storyboard.Children().Add(doubleAnimation)
storyboard.Children().Add(doubleAnimation1)
storyboard.Begin()
End Sub
Code: Select all
Slide from Right:
Public Sub SlideDownAni(ByVal sender As [Object])
DirectCast(sender, Button).Visibility = 0
Dim doubleAnimation As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
doubleAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(500))
doubleAnimation.From = -500
doubleAnimation.To = 0
doubleAnimation.RepeatBehavior = New RepeatBehavior("1")
DirectCast(sender, Button).Projection = New PlaneProjection()
doubleAnimation.EnableDependentAnimation = True
Dim storyboard As Windows.UI.Xaml.Media.Animation.Storyboard = New Windows.UI.Xaml.Media.Animation.Storyboard()
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation, (DirectCast(sender, Button)).Projection())
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation, "GlobalOffsetY")
storyboard.Children().Add(doubleAnimation)
storyboard.Begin()
End Sub
Code: Select all
Slide from Left:
Public Sub SlideRightAni(ByVal sender As [Object])
DirectCast(sender, Button).Visibility = 0
Dim doubleAnimation As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
doubleAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(500))
doubleAnimation.From = 500
doubleAnimation.To = 0
doubleAnimation.RepeatBehavior = New RepeatBehavior("1")
DirectCast(sender, Button).Projection = New PlaneProjection()
doubleAnimation.EnableDependentAnimation = True
Dim storyboard As Windows.UI.Xaml.Media.Animation.Storyboard = New Windows.UI.Xaml.Media.Animation.Storyboard()
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation, (DirectCast(sender, Button).Projection()))
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation, "GlobalOffsetX")
storyboard.Children().Add(doubleAnimation)
storyboard.Begin()
End Sub
Code: Select all
Slide Up:
Public Sub SlideLeftAni(ByVal sender As [Object])
DirectCast(sender, Button).Visibility = 0
Dim doubleAnimation As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
doubleAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(500))
doubleAnimation.From = -500
doubleAnimation.To = 0
doubleAnimation.RepeatBehavior = New RepeatBehavior("1")
DirectCast(sender, Button).Projection = New PlaneProjection()
doubleAnimation.EnableDependentAnimation = True
Dim storyboard As Windows.UI.Xaml.Media.Animation.Storyboard = New Windows.UI.Xaml.Media.Animation.Storyboard()
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation, (DirectCast(sender, Button).Projection()))
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation, "GlobalOffsetX")
storyboard.Children().Add(doubleAnimation)
storyboard.Begin()
End Sub
Code: Select all
Public Sub SlideUpAni(ByVal sender As [Object])
DirectCast(sender, Button).Visibility = 0
Dim doubleAnimation As Windows.UI.Xaml.Media.Animation.DoubleAnimation = New Windows.UI.Xaml.Media.Animation.DoubleAnimation()
doubleAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(500))
doubleAnimation.From = 500
doubleAnimation.To = 0
doubleAnimation.RepeatBehavior = New RepeatBehavior("1")
DirectCast(sender, Button).Projection = New PlaneProjection()
doubleAnimation.EnableDependentAnimation = True
Dim storyboard As Windows.UI.Xaml.Media.Animation.Storyboard = New Windows.UI.Xaml.Media.Animation.Storyboard()
Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(doubleAnimation, (DirectCast(sender, Button).Projection()))
Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(doubleAnimation, "GlobalOffsetY")
storyboard.Children().Add(doubleAnimation)
storyboard.Begin()
End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023