Skip to main content
Home Forums Silverlight Design Designing with Silverlight how to start an anamination and keep it running for ever?
9 replies. Latest Post by kent.zhou on November 2, 2009.
(0)
kent.zhou
Member
110 points
403 Posts
10-29-2009 1:48 PM |
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
Contributor
2171 points
342 Posts
10-29-2009 2:09 PM |
Hi
Use the repeat RepeatBehavior
<DoubleAnimation From="1.0" To="0.0" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"/>
prujohn
3579 points
704 Posts
10-29-2009 2:10 PM |
In Code-Behind:
myAnamination.RepeatBehavior = RepeatBehavior.Forever;
In Xaml:
<Storyboard x:Name="myAnamination" RepeatBehavior="Forever">
MawashiKid
627 points
117 Posts
10-29-2009 2:12 PM |
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>
10-29-2009 2:22 PM |
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
Participant
1544 points
217 Posts
10-29-2009 2:51 PM |
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?
10-29-2009 4:00 PM |
Hi Kent,clint1222 is right... you don't have to specify the RepeatBehavior both in your XAMLand 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 containsthe 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.
10-29-2009 4:29 PM |
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.
bharathk...
280 points
51 Posts
10-30-2009 2:06 AM |
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.
11-02-2009 10:15 AM |
Hi guys, thanks for help. After redo and recompile it again, it works now.