locked
Set Target Name and Property for GradientStops in vb.net

    Question

  • Hi all,

    im trying to create a linear gradient animation in vb.net but i dont get to specify the target name and property.

    The code looks something liket that, thanks for help

    Dim brushopacity As New LinearGradientBrush
            Dim fSpoint, fEpoint As New Windows.Foundation.Point
            Dim mediaS, mediaE, mediaT As New Media.GradientStop
            Dim colorS, colorE As New Windows.UI.Color

            fSpoint.X = 0
            fSpoint.Y = 0.5
            fEpoint.X = 1
            fEpoint.Y = 0.5

            colorS.A = 255
            colorE.A = 0

            mediaS.Offset = 0
            mediaS.Color = colorS
            mediaE.Offset = 1
            mediaE.Color = colorE
            ' Animation von 1 bis 0!
            mediaE.Offset = 0.5
            mediaT.Color = colorE


            brushopacity.StartPoint = fSpoint
            brushopacity.EndPoint = fEpoint
            brushopacity.GradientStops.Add(mediaS)
            brushopacity.GradientStops.Add(mediaE)
            brushopacity.GradientStops.Add(mediaT)

            testblock.Foreground = brushopacity


            Dim fadeIn As New Animation.DoubleAnimation

            fadeIn.From = 1.0
            fadeIn.To = 0.0
            fadeIn.Duration = New Duration(TimeSpan.FromSeconds(10))

            mystoryboard.Children.Add(fadeIn)
            Animation.Storyboard.SetTargetName(fadeIn,"mediaT" )
            Animation.Storyboard.SetTargetProperty(fadeIn, "Offset")


            GridMain.Resources.Add("mystoryboard", mystoryboard)

            mystoryboard.Begin()

    Tuesday, August 19, 2014 9:35 AM

Answers

  • Then you should pass mediaT as the second argument to the Storyboard.SetTarget method and the string "Offset" as the second argument to the Storyboard.SetTargetProperty method. You must also set the EnableDependentAnimation property of the DoubleAnimation to true:

            Dim brushopacity As New LinearGradientBrush
            Dim fSpoint, fEpoint As New Windows.Foundation.Point
            Dim mediaS, mediaE, mediaT As New Media.GradientStop
            Dim colorS As Windows.UI.Color = Windows.UI.Colors.White
            Dim colorE As Windows.UI.Color = Windows.UI.Colors.Black
    
            fSpoint.X = 0
            fSpoint.Y = 0.5
            fEpoint.X = 1
            fEpoint.Y = 0.5
    
            mediaS.Offset = 0
            mediaS.Color = colorS
            mediaE.Offset = 1
            mediaE.Color = colorE
            mediaE.Offset = 0.5
            mediaT.Color = colorE
    
    
            brushopacity.StartPoint = fSpoint
            brushopacity.EndPoint = fEpoint
            brushopacity.GradientStops.Add(mediaS)
            brushopacity.GradientStops.Add(mediaE)
            brushopacity.GradientStops.Add(mediaT)
    
            testblock.Foreground = brushopacity
    
            Dim fadeIn As New Animation.DoubleAnimation
            fadeIn.EnableDependentAnimation = True
            fadeIn.From = 1.0
            fadeIn.To = 0.0
            fadeIn.Duration = New Duration(TimeSpan.FromSeconds(10))
            Storyboard.SetTarget(fadeIn, mediaT)
            Storyboard.SetTargetProperty(fadeIn, "Offset")
    
            Dim mystoryboard As New Animation.Storyboard
            mystoryboard.Children.Add(fadeIn)
            mystoryboard.Begin()
    

    Please remember to mark any helpful replies as answer and/or helpful.

    • Marked as answer by Problem449 Wednesday, August 20, 2014 7:33 PM
    Wednesday, August 20, 2014 1:37 PM

All replies

  • Which property do you want to apply the animation to? You specify the name of this property using the Storyboard.SetTargetProperty method.
    Which object does this property belong to? You specify the object for which you want to apply the animation on using the StoryBoard.SetTarget method.

    For example, if you want to animate the Opacity property of a control called "testBlock", you would set call the methods like this:

    Storyboard.SetTarget(fadeIn, testBlock)
    Storyboard.SetTargetProperty(fadeIn, "Opacity")
    

    Tuesday, August 19, 2014 9:50 AM
  • I would want to run the gradient stop mediaT.offset from 1 to 0 and so have my testblock disappear from right to left within 10 seconds
    Tuesday, August 19, 2014 6:57 PM
  • Then you should pass mediaT as the second argument to the Storyboard.SetTarget method and the string "Offset" as the second argument to the Storyboard.SetTargetProperty method. You must also set the EnableDependentAnimation property of the DoubleAnimation to true:

            Dim brushopacity As New LinearGradientBrush
            Dim fSpoint, fEpoint As New Windows.Foundation.Point
            Dim mediaS, mediaE, mediaT As New Media.GradientStop
            Dim colorS As Windows.UI.Color = Windows.UI.Colors.White
            Dim colorE As Windows.UI.Color = Windows.UI.Colors.Black
    
            fSpoint.X = 0
            fSpoint.Y = 0.5
            fEpoint.X = 1
            fEpoint.Y = 0.5
    
            mediaS.Offset = 0
            mediaS.Color = colorS
            mediaE.Offset = 1
            mediaE.Color = colorE
            mediaE.Offset = 0.5
            mediaT.Color = colorE
    
    
            brushopacity.StartPoint = fSpoint
            brushopacity.EndPoint = fEpoint
            brushopacity.GradientStops.Add(mediaS)
            brushopacity.GradientStops.Add(mediaE)
            brushopacity.GradientStops.Add(mediaT)
    
            testblock.Foreground = brushopacity
    
            Dim fadeIn As New Animation.DoubleAnimation
            fadeIn.EnableDependentAnimation = True
            fadeIn.From = 1.0
            fadeIn.To = 0.0
            fadeIn.Duration = New Duration(TimeSpan.FromSeconds(10))
            Storyboard.SetTarget(fadeIn, mediaT)
            Storyboard.SetTargetProperty(fadeIn, "Offset")
    
            Dim mystoryboard As New Animation.Storyboard
            mystoryboard.Children.Add(fadeIn)
            mystoryboard.Begin()
    

    Please remember to mark any helpful replies as answer and/or helpful.

    • Marked as answer by Problem449 Wednesday, August 20, 2014 7:33 PM
    Wednesday, August 20, 2014 1:37 PM
  • Cool, thanks so much
    Wednesday, August 20, 2014 7:33 PM