locked
Lineargradientbrush Animation using Keyframes in vb.net

    Question

  • HI everyone,

    I am trying to write a Lineargradientbrush Animation using Keyframes in vb.net to Animate a textblock being blended out from left to right and blended in from right to left again after one second.  I managed with a similar code to do by linear double animation without keyframes but now for some reason I did something wrong in the transfer to a timed  linearkeyframeanimation. Thanks for any help

    Dim mystoryboard As Animation.Storyboard
    Dim brushopacity As New LinearGradientBrush
    Dim stopT1, stopT2, stopS, stopE As New Media.GradientStop
    Dim fadein1 As New Animation.DoubleAnimationUsingKeyFrames
    Dim fadein2 As New Animation.DoubleAnimationUsingKeyFrames
    Dim fSpoint, fEpoint As New Windows.Foundation.Point
    Dim colorS As Windows.UI.Color = Windows.UI.Colors.White
    Dim colorE As Windows.UI.Color = Windows.UI.Colors.Black
    Dim keyframe(2) As Animation.LinearDoubleKeyFrame

    Dim textblock as new textblock

            brushopacity = New LinearGradientBrush

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

            colorS = Windows.UI.Color.FromArgb(255, 0, 0, 0)
            colorE = Windows.UI.Color.FromArgb(0, 0, 0, 0)

            stopS.Offset = 0
            stopS.Color = colorS
            stopE.Offset = 1
            stopE.Color = colorE
            stopT1.Offset = 0.5
            stopT1.Color = colorS
            stopT2.Offset = 0.5
            stopT2.Color = colorE

            brushopacity.StartPoint = fSpoint
            brushopacity.EndPoint = fEpoint
            brushopacity.GradientStops.Add(stopS)
            brushopacity.GradientStops.Add(stopE)
            brushopacity.GradientStops.Add(stopT1)
            brushopacity.GradientStops.Add(stopT2)

            textblock.Foreground = brushopacity

            fadein1.EnableDependentAnimation = True
            fadein2.EnableDependentAnimation = True

            fadein1 = New Animation.DoubleAnimationUsingKeyFrames

            For i = 0 To 2
                keyframe(i) = New Animation.LinearDoubleKeyFrame
            Next

            keyframe(0).Value = 1
            keyframe(0).KeyTime = TimeSpan.FromSeconds(1)
            keyframe(1).Value = 1
            keyframe(1).KeyTime = TimeSpan.FromSeconds(2)
            keyframe(2).Value = 0
            keyframe(2).KeyTime = TimeSpan.FromSeconds(3)

            For i = 0 To 2
                fadein1.KeyFrames.Add(keyframe(i))
            Next

            fadein1.Duration = TimeSpan.FromSeconds(3)

            fadein2 = fadein1


            mystoryboard.Children.Add(fadein1)
            mystoryboard.Children.Add(fadein2)

            Animation.Storyboard.SetTarget(fadein1, stopT1)
            Animation.Storyboard.SetTargetProperty(fadein1, "Offset")
            Animation.Storyboard.SetTarget(fadein2, stopT2)
            Animation.Storyboard.SetTargetProperty(fadein2, "Offset")

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

            mystoryboard.Begin()

    Wednesday, March 04, 2015 11:21 PM

All replies

  • What’s wrong with your code? Something doesn’t work? Check this reference may help your question. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj819806.aspx.

    Thursday, March 05, 2015 9:31 AM
  • yes, unfortunately nothing happens:)
    Thursday, March 05, 2015 1:41 PM
  • Actually it seems like there is a tiny shift within the center between the red lines (see image where the grey color indicates indivisible text) I only have set the starting value of stopT1 and stopT2 to 0.5 so I could see at least something but I was hoping to have the text appear from the center to the right, see the full textblock for a second and and then see it dissappear from right to left. Thanks for any help



    • Edited by CM111 Thursday, March 05, 2015 11:13 PM
    Thursday, March 05, 2015 11:12 PM
  • Hi CM111,

    Can you submit a repro project to help troubleshooting on your OneDrvie? Thanks for your understanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 09, 2015 8:12 AM
    Moderator
  • Hi Herro wong,

    sorry I do not know how to do this. Also the posted code is only just a basic simplification of what I use in my script to show what commands I use. I could create a new project only with this code if that helps and somehow upload it but I thought I am just missing one basic thing or so:)

    Regards

    Monday, March 09, 2015 8:47 PM