As I was writing up a response to the questions on a forums post about using DomainDataSource from a ViewModel, I thought I should just publish the notes here.  I hope this helps people understand what will and will not work from the DomainDataSource when being used outside the visual tree.

I've heard many times that people are using the DomainDataSource in ViewModel scenarios.  Contrary to popular belief, this can work very well with the control as it is today; there are only a couple features that won't work outside the visual tree.  Aside from these two items, everything the DomainDataSource does is supported in a ViewModel.

AutoLoad

In order for auto-load to work, the control must be loaded into the UI tree.  Auto-loads are typically used when you have Filters, Sorts, and/or Query Parameters driven from UI controls.  The DomainDataSource will wait for control to get the Loaded event, and then dispatch the first auto-load.  Until that event occurs, all auto-loads are queued up.  When outside the visual tree, this Loaded event will never be raised and no auto-loads will ever occur.

Just because auto-loads won’t occur doesn’t mean you can’t use the DomainDataSource from a ViewModel.  Instead of relying on these automatic loads after changing property values, you can call the Load() method as needed.  With the Release Candidate of WCF RIA Services, we have relaxed the Load method such that it won’t throw exceptions if a load is already pending.  So if you call Load multiple times, we will cancel all but the last call.  Note that it is possible that the control will submit the load request to the server from a canceled load (and just ignore the response), but it should now be easier to programmatically call the Load method from your ViewModel.

ElementName Bindings

As I illustrated recently, DomainDataSource’s Filter, Sort, Group, and Query parameters now all support element name bindings for driving the control’s inputs from the UI.  These bindings won’t work when the control is not part of the visual tree or resources.  But chances are, if you’re using the DomainDataSource from a ViewModel, you aren’t trying to bind its inputs to UI elements.

RIA Services vNext

I’d love to hear more about your scenarios where the DomainDataSource isn’t working well for you when you’d like it to.  We’re working on our plans for the next version of RIA Services, so there’s no better time to share your feedback and suggestions!