none
How to chain animation RRS feed

  • Question

  • Hello,

     

    I've written following XAML and C#:

     

    There are defined animations of Opacity property according to IsEnabled. But: if I click the button (event handler on the bottom), first animation will not progress to its end and the second one begins directly. Is there any way, how to "force" animation to go to its end?

     

    Thank you.

     

    RostaB

     

     

     

     

    <Page x:Class="FadeInFadeOutExample.Page1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Page1"

    >

    <Page.Resources>

    <Style TargetType="Rectangle">

    <Style.Triggers>

    <Trigger Property="Rectangle.IsEnabled" Value="true">

    <Trigger.EnterActions>

    <BeginStoryboard>

    <Storyboard>

    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:5"/>

    </Storyboard>

    </BeginStoryboard>

    </Trigger.EnterActions>

    <Trigger.ExitActions>

    <BeginStoryboard>

    <Storyboard>

    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:5"/>

    </Storyboard>

    </BeginStoryboard>

    </Trigger.ExitActions>

    </Trigger>

    </Style.Triggers>

    </Style>

    </Page.Resources>

    <StackPanel Margin="10">

    <Rectangle

    Name="MyRectangle"

    Width="100"

    Height="100"

    Fill="Blue">

    </Rectangle>

    <CheckBox Name="MyCheckBox" Click="CheckBoxClick">IsEnabled</CheckBox>

    <Button Click="ButtonClick">Enable / Disable</Button>

    </StackPanel>

    </Page>

     

     

     

     

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Windows;

    using System.Windows.Controls;

    using System.Windows.Data;

    using System.Windows.Documents;

    using System.Windows.Input;

    using System.Windows.Media;

    using System.Windows.Media.Imaging;

    using System.Windows.Navigation;

    using System.Windows.Shapes;

    using System.Windows.Media.Animation;

    namespace FadeInFadeOutExample

    {

    /// <summary>

    /// Interaction logic for Page1.xaml

    /// </summary>

    public partial class Page1 : Page

    {

    public Page1()

    {

    this.InitializeComponent();

    }

     

    public void CheckBoxClick(object sender, EventArgs e)

    {

    this.MyRectangle.IsEnabled = !this.MyRectangle.IsEnabled;

    this.MyCheckBox.Content = this.MyRectangle.IsEnabled.ToString();

    }

     

    public void ButtonClick(object sender, EventArgs e)

    {

    this.MyRectangle.IsEnabled = false;

    this.MyRectangle.IsEnabled = true;

    }

    }

    }

     

     

     

    Monday, May 21, 2007 4:02 PM