Posts

Showing posts from March, 2022

How to Create Animation in WPF?

Image
  In some instances we need some animation to be shown in the User interface to improve the User Experience for example showing the progress bar indicating the live progress of some activity which is ongoing in the background. What is Animation? Animation is the process of changing the properties of an image/text such that it appears as moving in Realtime.  Animation helps to improve the overall user experience. In modern application we can see some kind of animation for every event which is happening in the application. Implementing Animation in WPF In this post lets understand how animation works in WPF with the help of Storyboard. Here we are going to discuss about basic animation like performing rotation of some shapes. Below code demonstrates the animation for the Spinner Control which is used to indicate that some background task is in progress. XAML Code In the above code we have taken an ellipse and made it into a circle with equal width and height. Since we are going ...

How to Load Data Asynchronously in WPF UI using MVVM Data Binding?

Image
  Most of the content which is displayed by the WPF Application is fetched from either the database or some Web service.  Why do we need to load Data Asynchronously? We might have seen that when we wait for the content to be available it tends to freeze our WPF Application/ Main Thread. Therefore to avoid that we need to fetch large content/Data in an asynchronous fashion from the Database or Remote Server. But the challenge there is how do we update the UI asynchronously. It is also desirable to show the loading progress to the user using some spinner control so that user gets the feeling that content is loading.  We know that if we query the Web service or the Windows Service for any result it returns a Task which encapsulates the result if we are using Asynchronous version of the API. We will not be able to do direct data binding with the task which is being returned as WPF does not supports it.  Evaluating Different ways to load data in an Async Fashion One way i...

Generating Code using T4 Text Template in .NET Framework

Image
  Automatic code generation is a emerging field in computer science where you will be able to generate the code which otherwise would have to be manually written by a software developer. Here we are going to discuss about basic tool from Microsoft known as T4 Text Template. There are many advanced code generation tools which uses latest technology such as AI to understand the user requirement and generate the piece of code based on a requirement. What is T4 Text Template? Here we are going to discuss about a simple tool which is less heard about in code generation space, known as T4 Template from Microsoft. Its a Open source toolkit for template based code generation. Source file has an extension ending with tt. Where T4 Text Template can be used? This would be helpful in cases where there is a requirement of large number of classes and properties to be generated, if we are manually going about coding these classes it would be tiring and will be prone to more errors. Here we w...