Well, it’s been a while since I first posted on this, but the feedback was incredible, and I got some great suggestions. As a result, I’ve updated the Activity control and (finally) have a running sample on the web! The fundamental idea of the control has remained the same, as well as the mechanisms by which it can work. It’s still a prototype, but a very useful one at that!
To see the Activity control in action, take a look here: Activity Control Demo
The demo requires the Silverlight 3 beta to be installed on your machine, which can be found here: http://silverlight.net/getstarted/silverlight3/default.aspx
The demo application shows two examples of using the Activity control to display async/background activity (click the images for deep-links into the Silverlight application):
- With .NET RIA Services and the DomainDataSource, the Activity control uses element-to-element binding to indicate to the user that data is being loaded or submitted. The demo page is running live on my server using the Northwind sample database. Those of you who think you can play some dirty tricks by overwriting the data on my server (yes, I provided insert/update/delete functionality) – any attempts to do so will be quickly foiled, since the server will accept the requests, but ignore them!
- Any background activity might warrant using the activity control. The second example I’ve provided uses the activity control while I use a simple statistical method of approximating PI (yes, very geeky). It takes millions of iterations to get a mediocre approximation of PI (I know, I’m not using an efficient method, but it does do a lot of work!). Here, I’ve augmented the Activity control to allow the work to be stopped/cancelled:
So by now I’m sure you’re asking: “What’s changed?” Well, let me tell you!
- Thanks to feedback from a variety of folks, I’ve removed the all-encompassing template that included the pop-up window. That’s now baked into the control template. If you’d like to change it, you can use the Blend 3 Preview to re-template the control. In its place, I’ve added:
- A style for the progress bar. If you’d like to hide it, use a style to collapse the progress bar.
- A means for setting “ActiveContent”. The Activity control works sort of like a HeaderedContentControl. You now have ActiveContent and ActiveContentTemplate, which allow you to define in XAML what should appear above the progress bar. You can put any content you like here, and it’s how I added the cancel button in my PI calculation example. This is also great because it allows you to easily change the text from “Loading…” to whatever you prefer simply be setting the ActiveContent property to the string of your choice!
- The default template for the ActivityControl now sets IsHitTestVisible and IsEnabled to false on its content immediately when IsActive becomes true. In my old prototype, this only happened when the Activity UI became visible, which meant users could continue to interact with the content while it was busy – a potentially dangerous combination if the user’s interactions can be overriden by the asynchronous work (such as editing values in a DataGrid when the data is being reloaded). This was from a suggestion by Luke Tigaris in the comments on my last post. Let me know what you think!
- You can now call ResetActivity() on the control to force it to honor the visibility of the control immediately rather than enforcing the display delay and minimum display time. This way, if a user cancels the background work, you can force the Activity UI to be hidden immediately.
Anyhoo, let me know what you think of the changes! I’ve gotten lots of great feedback on the control so far, and I’m sure folks will come up with more as time goes on.
- You can download the source for the control here: Activity Control Source
- You can also download the source for the demo here: Activity Control Demo
For both of these, you’ll need the Silverlight 3 Beta. The Demo application is built using .NET RIA Services.
P.S. Big thanks again to Corrina for providing the beautiful theme I used in my application.
P.P.S. Isn’t navigation and deep-linking in the Silverlight 3 Beta cool? That’s how I made those images link directly to the corresponding pages of my demo application. I may post more on this in the future. In the meantime, take a look at the code to see just how little it took to accomplish that! (hint: MainPage.xaml in the Silverlight Navigation Application project template that’s included with the Silverlight 3 Beta Tools for Visual Studio has pretty much everything that’s required)
Update 9/14/2009 – I’ve made a small update to the Activity control to fix a performance issue. You can find it here.













#1 by Rachida Dukes on June 11, 2009 - 7:35 pm
Thanks so much for your contribution, this control is really used in silverlight applications.
#2 by Fallon Massey on June 11, 2009 - 8:50 pm
Why would the activity control need to be SL3, shouldn’t it work in SL2 as well?
#3 by Fallon Massey on June 11, 2009 - 8:55 pm
It does work for SL2. Change the project
From This:
To This:
#4 by david.poll on June 11, 2009 - 9:22 pm
You can probably build the Activity control itself for SL2, but its usefulness is significantly limited because SL2 doesn’t have element-to-element binding. You’re more than welcome to use it with SL2 if you find it useful and can get it working
#5 by David Roh on June 12, 2009 - 2:03 am
Very nice David!
Thank you for sharing your hard work.
#6 by Klinger on June 12, 2009 - 8:19 am
Hi David.
It’s a great control.
My coding became much easier with this control.
Thanks a lot.
#7 by Thanigainathan on June 14, 2009 - 10:38 pm
Hi,
A cool post. Thanks for the demo. Will expect more posts from you .
Thanks,
Thani
#8 by HP on June 24, 2009 - 7:35 am
why your data form control comes with add, delete button, but the one that I am using, has only edit button. did I miss out anything here?
I can’t see any xaml difference or cs code difference. Can you give me some clue?
#9 by david.poll on June 27, 2009 - 3:04 pm
If I remember correctly, the DataForm control needs to have its ItemsSource bound to an editable collection (i.e.IList or a CollectionView that implements IEditableCollectionView, such as PagedCollectionView in the System.Windows.Data assembly) in order to get those add and delete buttons. Fundamentally, the DataForm control changes its behavior based upon the data that you give it as its source. It is also possible to bind the DataForm to a single item, in which case the add/remove buttons and the currency management buttons (back/forward) go away altogether.
#10 by Tom Beeby on July 1, 2009 - 9:27 pm
Hi David,
nice control, but:
The Activity control de-enables child controls (buttons and the like), and when you set IsActive = false, it returns the child controls to their original state.
the problem is, say i have a DataForm with ItemsSource bound to a collection. I set IsActive = true and call a data service. all the buttons are already de-enabled due to a null ItemsSource, but Activity control still saves this state. when the data service comes back i set the IsActive to false, and the Activity control returns it’s child controls to their original state, which is de-enabled. the DataForm is now bound to a real ItemsSource but the various child controls (forward / back buttons etc) are all de-enabled when they really should be enabled.
make sense? any ideas?
cheers,
tom
#11 by david.poll on July 2, 2009 - 1:52 am
Tom,
I’d love to take a look at the problem you’re experiencing. I have a hunch it’s either a problem with the way the DataForm works or a quirk using the VSM and storyboards to set IsEnabled (which, incidentally, is only being set on a wrapper for the content of the Activity control rather than doing any sort of setting/restoring of values). If you’d like, you can e-mail me a project that repro’s this, and I’ll take a look when I can: david dot poll at microsoft dot com
#12 by Tom Beeby on July 2, 2009 - 5:53 pm
just emailed you a repro
#13 by david.poll on July 11, 2009 - 9:18 pm
Ok, I’m still exploring a bit, but I can verify that this is still repro-ing with DataForm at the moment. I’ll look into it, and see if there’s any clean workaround.
#14 by PYA on August 19, 2009 - 9:03 am
Hi,
First of all, thx for this nice control, it’s way cleaner than using a ProgressBar. I’ve got only one problem, the same as Tom: when I set IsActive to false, my DataForm’s children appear disabled.
Everything re-enables when I click on a DataField. I tried to hack the problem by calling Focus() on the DataForm or on a DataField after setting IsActive to false, but it’s no use.
I thought it was because the Activity control restored the previous state, so I also tried to put a single item in the collection to which my DataForm is bound before setting IsActive to true and loading my data, in order to get an enabled DataForm as a previous sate, but in the end it didn’t help, so I guess the problem is a bit more subtle.
Have you found anything, do you have an idea where the problem could be?
#15 by Kevin on September 3, 2009 - 2:16 pm
Hi David,
Did you ever find a fix for this issue? I’m running into it too where I have a data form wrapped in an activity control and when the DataContext that the activity control is bound to comes out of the IsLoading state all of the items on the data form are disabled (until you click on one).
#16 by Daa on July 13, 2009 - 11:07 am
Great post.
Does the Activity control work only with RIA services? Can i trigger that any time i want, for other “Non RIA” background tasks?
#17 by david.poll on July 13, 2009 - 12:05 pm
Nope, the Activity control will work with any background task (you can just set IsActive on the control whenever you find it appropriate). The sample I posted actually does this for the “Heavy Async Work” of calculating PI
#18 by Алексей Андреевич on July 14, 2009 - 8:28 am
Поздравляю, замечательная мысль
#19 by Marcus on July 14, 2009 - 9:28 am
After converting a SL3Beta site to SL3, it appears Horizontal & Vertical Alignment set to “Stretch” for the Activity control don’t work. Can anyone else confirm? I have a simple page with a single-cell grid that takes up the whole screen. Placing a DataGrid in the cell and setting it to stretch does the trick, but wrapping the DataGrid with an Activity control set to Stretch leavs the DataGrid at it’s smallest possible size (header only) until it’s populated, and then it only grows to meet its needs.
#20 by david.poll on July 14, 2009 - 10:18 am
Marcus,
I just gave this a shot, but wasn’t able to see the same thing as you. Could you either post a XAML snippet of what you did or maybe e-mail me with a repro app? I’m happy to try to take a look
You can reach me at david dot poll at microsoft dot com.
-David
#21 by Charles Strahan on July 31, 2009 - 3:19 pm
Hi Marcus,
I just posted an identical comment below. I have the same layout as you describe, a Grid with the Activity inside of it, with a DataGrid below that. The DataGrid collapses and shows only the header.
Any luck getting it to expand?
-Charles
#22 by david.poll on July 31, 2009 - 3:33 pm
As you mentioned — the solution is below
#23 by Marcus on July 14, 2009 - 11:29 am
David,
The app is a RIA Services Business template. I’ve created a simple navigation page with this as the LayoutRoot grid:
The page displays with the green LayoutRoot stretching to fill all available space, but the Grid stays at minimum size (just the header while loading, adding the rows once loaded), but never stretches to fill the available space.
To verify, I placed the exact code on my box that is still SL3 Beta and the activity control (and datagrid) stretches as expected to fill the whole LayoutRoot.
Thanks.
#24 by david.poll on July 14, 2009 - 11:49 am
Very strange… This seems to be a nuance of the Business template from RIA Services, since it doesn’t happen if I use identical XAML in the vanilla navigation template.
A temporary workaround (I’ll try to find out what’s going on): set HorizontalContentAlignment and VerticalContentAlignment on the Activity control to stretch.
#25 by david.poll on July 14, 2009 - 11:58 am
Ok, more info for you: the Business template seems to include a precompiled version of the Activity control in the libs folder. This one appears to be causing the problem. If you build it from my projects above and replace the dll with this one, it seems to fix the problem. I’m going to get in contact with the RIA services guys and let them know what’s going on.
#26 by montu82 on July 22, 2009 - 1:42 pm
I downloaded and built the project from the activity source code above and replaced the dll file in the Libs folder and my datagrid is still not showing the correct width? Any suggestions? I also used the silverlight business template.
#27 by Charles Strahan on July 31, 2009 - 3:30 pm
Excellent! That did the trick.
Thanks,
-Charles
#28 by david.poll on July 31, 2009 - 3:33 pm
Yep — I’ll be posting about this soon. The business template has an old version of the Activity control in it — if you use the most recent one from my site, this problem is fixed. We’ll make sure the Business Application Template gets updated for future releases
#29 by Russell Pooley on July 14, 2009 - 4:19 pm
I have looked at your control and it is superb, the only problem I have is that it doesn’t seem to work in a SL3 navigation application.
I have copied the PI sample into my application and when I click on the calculate PI nothing appears. Quite bizarre.
#30 by david.poll on July 14, 2009 - 5:18 pm
That doesn’t sound right… the sample I have above IS an SL3 navigation application. I’d have to know more details of what you actually copied into your app to know what’s going on. More details would be very welcome
#31 by Russell Pooley on July 15, 2009 - 2:53 am
I have copied the Activity.cs and the default.theme.
I changed the namespaces and updated both the Activity and theme to reflect this change.
you can see it happening @ http://www.mobiess.com/demo and click on the About link and then you will see the PI example you created.
I will do a little bit of debugging to see if I can figure it out.
#32 by Klinger on July 15, 2009 - 9:02 pm
Hi David,
I have gone back to the control you posted here
as the one shipped with RIA Services, besides
the problem with Horizontal/VerticalAlignment,
also doesn’t expose the ActivityContent property.
I haven’t checked to see if the RIA one is missing
any other feature.
Thanks,
Klinger
#33 by david.poll on July 16, 2009 - 12:33 am
Yeah, I talked to the RIA services folks. I think they’re using an old version of the control in their project template. We’ll try to make sure this gets resolved in some way going forward.
#34 by Charles Strahan on July 31, 2009 - 3:15 pm
Hi Dadid,
This is an excellent control. I have a quick question though regarding the layout of the control’s content.
I currently have a page with a DataGrid inside of a Grid. The RowDefinition’s height is set to “*”, causing the grid to expand and fill the page. If I place the Activity control around the DataGrid, the DataGrid collapses, causing it to be centered on the page.
Do you know if there’s a way I can use Activity and still have it fill the Grid?
Cheers,
-Charles
#35 by dev on January 5, 2010 - 12:51 pm
I have a question about SL3 PagedCollectionView and wonder if you could help. I have the following code and the data enter on 1 page and copied over to another page on the same row number. Is this a bug? is there a workaround?
PagedCollectionView pagedCollectionView = new PagedCollectionView(e.Result);
dataGridBike.ItemsSource = pagedCollectionView;
dataForm1.ItemsSource = pagedCollectionView;
// populate employee info
ObservableCollection bikes = new ObservableCollection();
//PagedCollectionView bikeView = pagedCollectionView;
bikes = (ObservableCollection)pagedCollectionView.SourceCollection;
#36 by david.poll on January 5, 2010 - 1:21 pm
I’m not sure I understand what you’re trying to accomplish with your code. Can you perhaps provide some additional detail?