Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Storyboard.SetTarget does not work in SL2
5 replies. Latest Post by slide.gt on November 10, 2008.
(0)
slide.gt
Member
2 points
10 Posts
11-07-2008 6:36 PM |
I have searched in this forum and got similiar topic but there's no solution for this problem.Please help me.
The point is, i want to make my storyboard useable for any element.
Example : I have a storyboard name "mouseovertimeline" ,image1 and image2 .And i want to make this storyboard can be used on any element such as image1 and image2.
Here is a piece of my coding i got from another topic in this forum :
private void mouseovers(object sender, MouseEventArgs e) { mouseovertimeline.Stop(); Storyboard.SetTarget(this.mouseovertimeline, this.image1); mouseovertimeline.Begin(); }
when i run this project, error comes out say "Cannot resolve TargetProperty (UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX) on specified object."
really appreciate for any help.
Glenn T
jakkaj
Participant
934 points
146 Posts
11-07-2008 6:50 PM |
Hi,
You may need to add the RenderTransform XAML below the target element first.
<Image.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="0"/> <TranslateTransform/> </TransformGroup> </Image.RenderTransform>
You can also create these in code behind if needed:
TransformGroup tg = new TransformGroup();element.RenderTransform = tg; ScaleTransform st = new ScaleTransform();tg.Children.Add(st);
... and so on.
11-07-2008 7:14 PM |
hi jakkaj, thanks for ur response but it seems doesn't work.Actually i prefer using Storyboard.SetTarget rather than other. I'm really curious why this code doesn't work in my silverlight 2 project.actually in my storyboard named "mouseovertimeline" has animation already and the thing is, i just want to change the targetname in c#.
Sorry if there's something wrong, i'm just totally new in Silverlight
Thanks for any help.
Priyamjm
234 points
32 Posts
11-10-2008 3:56 PM |
//Try this
<UserControl x:Class="SilverlightApplicationTest2.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="Black"> <StackPanel Orientation="Horizontal"> <Button x:Name="Btn1" Content="Hello1" Height="50" Width="50" Click="Btn1_Click"> <Button.RenderTransform> <ScaleTransform ScaleX="1.0" ScaleY="1.0" /> </Button.RenderTransform> </Button> <Button x:Name="Btn2" Content="Hello1" Height="50" Width="50" Click="Btn2_Click"> <Button.RenderTransform> <ScaleTransform ScaleX="1.0" ScaleY="1.0" /> </Button.RenderTransform> </Button> </StackPanel> </Grid> <UserControl.Resources> <Storyboard x:Name="sb1"> <DoubleAnimation x:Name="da1" Storyboard.TargetProperty="(Button.RenderTransform).(ScaleTransform.ScaleX)" From="1.0" To="2.0" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever" /> </Storyboard> </UserControl.Resources></UserControl>
private void Btn1_Click(object sender, RoutedEventArgs e) { sb1.Stop(); Storyboard.SetTarget(da1, Btn1); sb1.Begin(); } private void Btn2_Click(object sender, RoutedEventArgs e) { sb1.Stop(); Storyboard.SetTarget(da1, Btn2); sb1.Begin(); }
11-10-2008 8:29 PM |
thanks Priyamjm, I will try that code. I will inform you whether it is working or not.
11-10-2008 9:17 PM |
wow..it's working.thanks alot Priyamjm.really appreciate your help.