Live Chat Icon For mobile
Live Chat Icon

How do I trigger an animation when the data in the control is changed?

Platform: WPF| Category: Animation

Animations can be applied to the objects in WPF application when the data in the control changes using the DataTriggers. The following lines of code is used to apply animations using a DataTrigger

[XAML]

<TextBlock Text='WPF Application' Name='tb1' Foreground='Blue' FontSize='28' TextAlignment='Center' Height='50' VerticalAlignment='Top'>
<TextBlock.Style>
      	<Style>
            <Style.Triggers>
<DataTrigger Binding='{Binding ElementName=cb1,Path=IsChecked}' Value='true'>
                  <DataTrigger.EnterActions>
                  <BeginStoryboard>
                  <Storyboard>
<DoubleAnimation Storyboard.TargetProperty='Opacity' From='0' To='1' Duration='0:0:1' AutoReverse='True' RepeatBehavior='Forever' />
                  </Storyboard>
                  </BeginStoryboard>
                  </DataTrigger.EnterActions>
                  <DataTrigger.ExitActions>
                  <BeginStoryboard> 
                  <Storyboard FillBehavior='Stop'>
<DoubleAnimation Storyboard.TargetProperty='Opacity' To='1' Duration='0:0:1' />
                  </Storyboard>
                  </BeginStoryboard>  
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<CheckBox Name='cb1' Content='Show Animation' IsChecked='True' Height='30' HorizontalAlignment='Center' />

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.