CREATE A SIMPLE NUMBERS LOADING ANIMATION USING C# IN SILVERLIGHT:

CREATE A SIMPLE NUMBERS LOADING ANIMATION USING C# IN SILVERLIGHT:

       Hi,  Here i am  explain how to create a simple  numbers loading animation.
And here the number will be loaded from '0' to '100'

Step 1:

     
     Create a button(name btnnumber) and label(name lblnumber)

Step 2:


     Here we are going to do that by  DispatcherTimer class. It is from the following name space
      using System.Windows.Threading; 

What is dispatch timer? How to use that?

 

     DispatcherTimer is a class that is used to call a function in a particular  time interval. see the below example(we should use within any function)

        DispatcherTimer timer= new DispatcherTimer ();
            timer.Tick += delegate(object s, EventArgs args)
            {
               //write code here for what should call after 1 sec
              //after that don't forget to call the method(where you want to stop the timer)-> timer.Stop();
            };             
                          
            timer.Interval = new TimeSpan(0, 0, 1); // one second , you can change the time here
            timer.Start(); // here the timer will be started


 Step 3:


       Include the following name space->      using System.Windows.Threading; 
and declare a variable->       int animat_number = 0; 
And with in the buttion click function write the DispatcherTimer class codes


Here this is the code with in the button click function.

    private void btnnumber_Click(object sender, RoutedEventArgs e)
        {
            DispatcherTimer timer = new DispatcherTimer();

            timer.Tick += delegate(object s, EventArgs args)
                {
                    lblnumber.Content = animat_number;
                    animat_number++;
                    if (animat_number > 100)
                    {
                        animat_number = 0;
                        timer.Stop();
                    }
                };

            timer.Interval = new TimeSpan(0, 0, Convert.ToInt32(0.25)); // 0.25 second
            timer.Start();
        } 

Step 4:

     Just hit f5, or run the program. click the button. and the numbers will be loaded from 0 to 100.

 Thank you for reading this.Kindly give your suggestions 

Reference: 

 see the following microsoft link

Comments

Popular posts from this blog

Add content type to SharePoint List/Library using REST API

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error