Skip to main content

Microsoft Silverlight

Answered Question how to start an anamination and keep it running for ever?RSS Feed

(0)

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

how to start an anamination and keep it running for ever?

Suppose I have a storyboard named as "myAnamination". I start it in code like

myAnamination.Begin();

But I want to this anamination keep runing for ever. How to do it? Any way set it in xaml with no code behind?

swo
swo

Contributor

Contributor

2161 points

342 Posts

Re: how to start an anamination and keep it running for ever?

Hi

Use the repeat RepeatBehavior

<DoubleAnimation From="1.0" To="0.0" Duration="0:0:1" 
  AutoReverse="True" RepeatBehavior="Forever"/>
 

If this has answered your question, please click on "mark as answer" on this post. Thank you!

Wolfgang (SWO) - www.EasyByte.at


prujohn
prujohn

Contributor

Contributor

3579 points

704 Posts

Answered Question

Re: how to start an anamination and keep it running for ever?

In Code-Behind:

myAnamination.RepeatBehavior = RepeatBehavior.Forever;

 

In Xaml:

<Storyboard x:Name="myAnamination" RepeatBehavior="Forever">
 

MawashiKid
MawashiKid

Member

Member

627 points

117 Posts

Re: how to start an anamination and keep it running for ever?

You can use the  RepeatBehavior="Forever"
property

XAML
---------


<Storyboard>
  <DoubleAnimation From="1.0" To="0.0" Duration="0:0:1"
    AutoReverse="True" RepeatBehavior="Forever" /><----------
</Storyboard>

 

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

Re: how to start an anamination and keep it running for ever?

 Thanks, guys.I created a user control as below:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
     x:Class="ACTRA.UI.Controls.AlertIcon"
    d:DesignWidth="122" d:DesignHeight="35">
    <UserControl.Resources>
        <Storyboard x:Name="IconFlashing" RepeatBehavior="Forever" AutoReverse="True" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Opacity)">
                <EasingDoubleKeyFrame KeyTime="00:00:00.9000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <StackPanel/>
        <Image x:Name="image"  HorizontalAlignment="Left" Margin="22,0,0,0" Width="122" Height="35" VerticalAlignment="Center" Source="/MyImages;component/Images/alert.png"  Cursor="Hand">
            <Image.Effect>
                <DropShadowEffect Opacity="0.1" Color="White" BlurRadius="10" ShadowDepth="0.0"/>
            </Image.Effect>
        </Image>
    </Grid>
</UserControl>

Code behind:

    public partial class AlertIcon : UserControl
    {
        public AlertIcon()
        {
            InitializeComponent();
            IconFlashing.Begin();
            IconFlashing.RepeatBehavior = RepeatBehavior.Forever;
        }
    }

Then I use this control in another control in xaml like:

<Controls:AlertIcon />

 But the animation did not run. why?

 

 

 

 

clint1222
clint1222

Participant

Participant

1544 points

217 Posts

Answered Question

Re: how to start an anamination and keep it running for ever?

Hi Kent,

You don't have to specify the RepeatBehavior twice (both in xaml and code).  Your code works fine.  On what color background are you displaying the icon?

MawashiKid
MawashiKid

Member

Member

627 points

117 Posts

Re: how to start an anamination and keep it running for ever?

 Hi Kent,

clint1222 is right...
you don't have to specify the RepeatBehavior both in your XAML
and CODE BEHIND... it's redundant.

I've checked your code and it worked pretty well in my case... No problemo.
I simply used a red Stop Sign icon as an image...
and changed the Dropshadow color to Red...

From
<DropShadowEffect Opacity="0.1" Color="White" BlurRadius="10" Shin adowDepth="0.0"/>
To
<DropShadowEffect Opacity="0.1" Color="Red" BlurRadius="10" ShadowDepth="0.0"/>

so I could see it better on a "White" Background on the main page that contains
the Controls:AlertIcon...

<Grid x:Name="Layout" Background="White">
   <Controls:AlertIcon  Width="300" Height="300"/>
</Grid>

Otherwise I wouldn't have been able to see the White Dropshadow animation at all or barely...  

Ran the code and haven't encountered any error.

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

Re: how to start an anamination and keep it running for ever?

 Thank you. With my trying, the animation only run one time, not reverse, because it runs very fast, I can only the the effective with blurrng. No dynamic back and forth. Very confused.

bharathkumars87
bharathk...

Member

Member

280 points

51 Posts

Re: Re: how to start an anamination and keep it running for ever?

 

Setting The Repeat Behavior

ClickOnState

The next step is key. Click on the State  in the Objects and Timeline, which will bring up the Common Properties window in the Properties area…

 

 

 

 

 

… so that you can click on AutoReverse, and Repeat Behavior of Forever.

SetRepeatBehavior

 

 

 

bharath kumar.s
Please "Mark as Answer" if this post answered your question. :)

kent.zhou
kent.zhou

Member

Member

110 points

403 Posts

Re: Re: how to start an anamination and keep it running for ever?

 Hi guys, thanks for help. After redo and recompile it again, it works now. 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities