5 Replies - 5982 Views - Last Post: 16 October 2010 - 05:41 AM

#1 begbodyguard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 15-February 10

Create new storyboard in code

Posted 10 October 2010 - 11:23 AM

I searched the on google for it and I did find some codes but they are all written in C# and i'm working in VB.
I tried to search on my own but I just don't find it here is wat I 'Have'
    Dim Storyobj1to2 as Storyboard
        Dim Framesobj1 as Animation.DoubleAnimationUsingKeyFrames
               
        l.Duration = "0:0:1.3"
        
    Dim frame1 as Animation.EasingDoubleKeyFrame
        frame1.KeyTime = '0:0:0.5"
        frame1.Value ="0.75"
                Framesobj1.KeyFrames.Add(frame1)

As you can see it's almost nothing.
Im pretty new to silverlight so I still have to search for most things.
Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Create new storyboard in code

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,863
  • Joined: 27-December 08

Re: Create new storyboard in code

Posted 10 October 2010 - 06:12 PM

So what exactly is your question?
Was This Post Helpful? 0
  • +
  • -

#3 begbodyguard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 15-February 10

Re: Create new storyboard in code

Posted 11 October 2010 - 09:12 AM

View Postmacosxnerd101, on 10 October 2010 - 05:12 PM, said:

So what exactly is your question?

How to create a (new) storyboard by using code. With that I mean when i pressed a button or something like that there should be created a (new) storyboard , I know it's possible because I have seen codes but were written in another language.
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Create new storyboard in code

Posted 11 October 2010 - 02:35 PM

since you didn't state what type of animation, here is some sample code on creating a fade-in/fade-out animation. I use this code as extension methods so that it will be available to all UIElements

// because I am doing these as extension methods, they
//   will be available to all UIElement objects, which are
//   basically all controls that can be added to the GUI
public static class ControlAnimationExtensionMethods
{
    public static void FadeIn(this UIElement targetControl)
    {
        DoubleAnimation fadeInAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1.5)));
        Storyboard.SetTarget(fadeInAnimation, targetControl);
        Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
        Storyboard sb = new Storyboard();
        sb.Children.Add(fadeInAnimation);
        sb.Begin();
    }

    public static void FadeOut(this UIElement targetControl)
    {
        DoubleAnimation fadeInAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(1.5)));
        Storyboard.SetTarget(fadeInAnimation, targetControl);
        Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
        Storyboard sb = new Storyboard();
        sb.Children.Add(fadeInAnimation);
        sb.Begin();
    }
}



EDITED: read all of the first post after I posted this. Here is the code above converted to VB.Net using Telerik's online code converter...

' because I am doing these as extension methods, they
'   will be available to all UIElement objects, which are
'   basically all controls that can be added to the GUI
Public NotInheritable Class ControlAnimationExtensionMethods
	Private Sub New()
	End Sub
	<System.Runtime.CompilerServices.Extension> _
	Public Shared Sub FadeIn(targetControl As UIElement)
		Dim fadeInAnimation As New DoubleAnimation(0, 1, New Duration(TimeSpan.FromSeconds(1.5)))
		Storyboard.SetTarget(fadeInAnimation, targetControl)
		Storyboard.SetTargetProperty(fadeInAnimation, New PropertyPath(UIElement.OpacityProperty))
		Dim sb As New Storyboard()
		sb.Children.Add(fadeInAnimation)
		sb.Begin()
	End Sub

	<System.Runtime.CompilerServices.Extension> _
	Public Shared Sub FadeOut(targetControl As UIElement)
		Dim fadeInAnimation As New DoubleAnimation(1, 0, New Duration(TimeSpan.FromSeconds(1.5)))
		Storyboard.SetTarget(fadeInAnimation, targetControl)
		Storyboard.SetTargetProperty(fadeInAnimation, New PropertyPath(UIElement.OpacityProperty))
		Dim sb As New Storyboard()
		sb.Children.Add(fadeInAnimation)
		sb.Begin()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#5 begbodyguard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 15-February 10

Re: Create new storyboard in code

Posted 12 October 2010 - 12:48 PM

Thanks will take a look at this in the weekend.
I don't have enough time to solve some of the errors right now. If I find it I will post it here.
Was This Post Helpful? 0
  • +
  • -

#6 begbodyguard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 15-February 10

Re: Create new storyboard in code

Posted 16 October 2010 - 05:41 AM

I have tried to make some changes. The fade out effect is working (for now) but it looks it doesn't stop
-> He doesn't show the message.
Private Sub FadeOut(targetControl As UIElement)
        Dim fadeOutAnimation As New DoubleAnimation
        fadeOutAnimation.From = 1
        fadeOutAnimation.To = 0
        Dim duration As New Duration(TimeSpan.FromSeconds(1.5))
        fadeOutAnimation.Duration = duration
        Storyboard.SetTarget(fadeOutAnimation, targetControl)
        Storyboard.SetTargetProperty(fadeOutAnimation, New PropertyPath(UIElement.OpacityProperty))
        Dim sb As New Storyboard()
        sb.Children.Add(fadeOutAnimation)
        sb.Duration = duration
        sb.Begin()  
Messagebox.show("End of animation")      
            End Sub


for FadeIn it doesn't work at all.
	Private Sub FadeIn(targetControl As UIElement) 
				Dim fadeInAnimation As New DoubleAnimation
		fadeInAnimation.From = 0
				fadeInAnimation.To = 1
		messagebox.show("test")
		Dim duration As New Duration(TimeSpan.FromSeconds(1.5))
		fadeInAnimation.Duration = duration
		Storyboard.SetTarget(fadeInAnimation, targetControl)
		Storyboard.SetTargetProperty(fadeInAnimation, New PropertyPath(UIElement.OpacityProperty))
		Dim sb As New Storyboard()
		sb.Children.Add(fadeInAnimation)
		sb.Begin()		
	End Sub

What am I doing wrong?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1