Mega Code Archive

 
Categories / VB.Net Tutorial / WPF
 

Remove Animations with Storyboard

<Window x: Class="WpfApplication1.Window1"   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   Title="" Height="300" Width="300">   <Window.Resources>     <Storyboard x:Key="Storyboard1">       <ParallelTimeline>         <DoubleAnimation x:Name="Animation1" Storyboard.TargetProperty="Width" From="140" To="50"           AutoReverse="True" RepeatBehavior="Forever" />         <DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" AutoReverse="True" RepeatBehavior="Forever" />       </ParallelTimeline>     </Storyboard>   </Window.Resources>   <UniformGrid>     <Button Content="Method 4" Click="Button4_Click" Loaded="Button4_Loaded" />   </UniformGrid> </Window> //File:Window.xaml.vb Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Media.Animation Namespace WpfApplication1   Public Partial Class Window1     Inherits Window     Public Sub New()       InitializeComponent()     End Sub     Private method4Storyboard As Storyboard     Private Sub Button4_Loaded(sender As Object, e As RoutedEventArgs)       method4Storyboard = TryCast(TryFindResource("Storyboard1"), Storyboard)       method4Storyboard.Begin(TryCast(sender, FrameworkElement), True)     End Sub     Private Sub Button4_Click(sender As Object, e As RoutedEventArgs)       If method4Storyboard IsNot Nothing Then         method4Storyboard.Remove(TryCast(sender, FrameworkElement))       End If     End Sub   End Class End Namespace