Skip to main content

Microsoft Silverlight

Answered Question Storyboard.SetTarget does not work in SL2RSS Feed

(0)

slide.gt
slide.gt

Member

Member

2 points

10 Posts

Storyboard.SetTarget does not work in SL2

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

 

 

o

jakkaj
jakkaj

Participant

Participant

934 points

146 Posts

Re: Storyboard.SetTarget does not work in SL2

 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.

http://blog.webjak.net
http://www.sddn.org.au

slide.gt
slide.gt

Member

Member

2 points

10 Posts

Re: Re: Storyboard.SetTarget does not work in SL2

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
Priyamjm

Member

Member

234 points

32 Posts

Answered Question

Re: Storyboard.SetTarget does not work in SL2

//Try this Smile

 <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();
}

slide.gt
slide.gt

Member

Member

2 points

10 Posts

Re: Storyboard.SetTarget does not work in SL2

 thanks Priyamjm, I will try that code. I will inform you whether it is working or not.

slide.gt
slide.gt

Member

Member

2 points

10 Posts

Re: Re: Storyboard.SetTarget does not work in SL2

 wow..it's working.thanks alot Priyamjm.really appreciate your help.

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities