Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1081147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:07:46+00:00 2026-05-16T22:07:46+00:00

I am new to WPF. I am creating a animation for sample online test

  • 0

I am new to WPF. I am creating a animation for sample online test result. Where I like to show No of attended question, No of correct answer as animation. I need to create small delay between AttendedQuestionEffect() and RightAnswerEffect();

CodeBehind code here

        public int TotalNoQuestion { get; set; }
        public int NoOfQuestionAttended { get; set; }
        public int NoOfRightAnswer { get; set; }

    public Window1()
    {
        InitializeComponent();

        TotalNoQuestion = 100;
        NoOfQuestionAttended = 18;
        NoOfRightAnswer = 10;

        stkpnl.Background = CreateLinearGradientBrush();

        Storyboard strBrd = new Storyboard();
        strBrd.Completed += new EventHandler(strBrd_Completed);
        DoubleAnimation myDoubleAnimation = new DoubleAnimation();
        myDoubleAnimation.From = 10;
        myDoubleAnimation.To = (TotalNoQuestion *15);
        myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
        Storyboard.SetTargetName(myDoubleAnimation, stkpnl.Name);
        Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(StackPanel.HeightProperty));
        strBrd.Children.Add(myDoubleAnimation);
        strBrd.Begin(stkpnl);

    }       

    void strBrd_Completed(object sender, EventArgs e)
    {

        for (int i = 1; i < TotalNoQuestion; i++)
        {
            Border brd = new Border();
            brd.BorderBrush = Brushes.Black;
            brd.BorderThickness = new Thickness(1.0);
            TextBlock txt = new TextBlock();
            txt.Text = i.ToString();
            txt.Height = 15;
            txt.Width = 200;
            brd.Child = txt;
            txt.FontSize = 12;
            txt.Foreground = Brushes.Black;
            stkpnl.Children.Add(brd);
            txt.Background = CreateLinearGradientBrush();
            txt.Tag = i.ToString();
        }

        AttendedQuestionEffect();
        // Here i need to create delay.
        RightAnswerEffect();
    }
    void AttendedQuestionEffect()
    {
        int index = 1;
        UIElementCollection ulCollection = stkpnl.Children;
        foreach (UIElement uiElement in ulCollection)
        {
            if (index <= NoOfQuestionAttended)
            {
                Border brd = (Border)uiElement;
                TextBlock txt = (TextBlock)brd.Child;
                txt.Background = BlinkEffect(Colors.Blue, Colors.SteelBlue, 3000);
                brd.Child = txt;
            }
            index++;
        }

    }

    void RightAnswerEffect()
    {
        int index = 1;
        UIElementCollection ulCollection = stkpnl.Children;
        foreach (UIElement uiElement in ulCollection)
        {
            if (index <= NoOfRightAnswer)
            {
                Border brd = (Border)uiElement;
                TextBlock txt = (TextBlock)brd.Child;
                txt.Background = BlinkEffect(Colors.Red, Colors.Blue, 1500);
                brd.Child = txt;
            }
            index++;
        }

    }

    private LinearGradientBrush CreateLinearGradientBrush()
    {
        LinearGradientBrush brush = new LinearGradientBrush();
        brush.StartPoint = new Point(0, 0);
        brush.EndPoint = new Point(1, 1);
        brush.GradientStops.Add(new GradientStop(Colors.LightCoral, 0.1));
        brush.GradientStops.Add(new GradientStop(Colors.YellowGreen, 0.35));
        brush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.86));
        return brush;
    }

    private SolidColorBrush BlinkEffect(Color startColor, Color endColor,int time)
    {
        ColorAnimation myColorAnimation = new ColorAnimation();
        myColorAnimation.From = startColor;
        myColorAnimation.To = endColor;
        myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(time));
        myColorAnimation.AutoReverse = true;
        myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;
        SolidColorBrush myBrush = new SolidColorBrush();
        myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
        return myBrush;
    }







**Xaml code here..**

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border BorderBrush="Black" Grid.Column="1" BorderThickness="1" Width="200" VerticalAlignment="Bottom" HorizontalAlignment="Left">
        <StackPanel x:Name="stkpnl" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Background="BlueViolet" Width="200" MaxHeight="450" >
        </StackPanel>
            </Border>
    </Grid>

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:07:46+00:00Added an answer on May 16, 2026 at 10:07 pm

    Your should look up storyboard animations using KeyFrames e.g. here.

    In Xaml this could look like the following … you just have to translate it to code and adjust it to your needes:

    <Storyboard>
        <DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Opacity">
            <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="0:0:0.5" Storyboard.TargetProperty="Visibility">
            <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}"/>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    

    This sample tfirst fades out an control and then hides it. You can ad a delay by modifying the BeginTime attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.