Sunday, September 9, 2012

Showing Busy Indicator while processing Background

Problem :
               In my last post “Fetch/Retrieve Entity Using Query Expression” I have just added data grid control and on top right side on the data grid control was the refresh button which was not working, but in this post I will do some work so for refresh button and show busy indicator to the end users.

Solution :
               For this I have added the busy indicator control of the silver light and used the one of the style which I have created for the silver light busy indicator control.I have placed in the Themes folder of the project with name “BusyIndicatorStyle.xaml” dictionary.I have used same approach which is used in the post (from where I get the style of the data grid). Where he used the command to bind the refresh button so that we can perform action based on the command on the view model and command is bind in the data grid style and if you don’t have any command defined in your view model nothing will happened mean no error or exception is thrown. The delegate command class which is taken from original post of the data grid style is placed in the "Classes" folder of the project.You can see the busy indicator while fetching the records as shown in Image 1.

Image 1
Let us start with the code which I have added for the busy indicator mean the xaml and the properties which are added in the view model used to bind the is busy and busy content properties of the busy indicator control.In List 1 you can see I have pasted only the xaml related to the busy indicator control, here you can see that I have bind the IsBusy and BusyContent of the busy indicator control which are the properties in the main view model class.

List 1

In List 2 you can see that I have pasted the code which I have added for the busy indicator control and also the command of the “Refresh” button on the top right side of the data grid control. Here you can see the first property is the IsBusy of type Boolean which is bind with the IsBusy property of the busy indicator control as you can see in the List 1 (the xaml code for the busy indicator control). Here you can see the default value of the IsBusy property in the view model is false(when we send the async call to fetch the record which will set it to true which mean the busy indicator control will be shown and on call back function value is set to false mean busy indicator control will be hide).

List 2

The second property in the view model code as shown in the List 2 is the BusyContent property of type string which is bind with the BusyContent property to show the message to the user what is happening in the background. Default value of the BusyContent property is “Loading Account records…” and I have modified the message when we click the refresh button on the data grid control “Refreshing Account List...” is the message which will be shown to the user when he/she click the refresh button. Defining the property for the Busy content here is to show the message to user you can remove this property and hard code the message on the xaml end but as you have multiple operation on the view model so it is better to show different message based on operation.
The last is the command which is bind with the refresh button of the data grid control. Which is taken from the original post and here I have added my code in the function to call the getAccountList function and before that statement I have changed the value of the BusyContent property to “Refresh Account List…”.

Note: The data grid style used in this example is taken from following link

Downloads
You can download the source code of the sample from here.
and working CRM 2011 solution from here.

Go to Home

All and any comments / bugs / suggestions are welcomed!

No comments: