I’m writing an app that connects to network resources.
When the app is connecting, I want to popup an overlay with the usual spinney progress graphic and a cancel button. I have designed a ConnectProgressViewModel and matching ConnectProgressView for the overlay.
My question is what is the cleanest way to show/hide the overlay from the parent ViewModel?
A) Expose a constant ConnectProgressViewModel from my parent ViewModel, and have the ConnectProgressView bind its visibility to the ConnectProgressViewModel.IsConnecting property.
B) Expose a generic Overlay property from the parent ViewModel, and set it to a ConnectProgressViewModel when the user wants to connect. The parent View binds a ContentControl to this Overlay property and data templating takes care of the rest.
C) ?
The first seems to encapsulate the functionality more, with the app not having to care about showing and hiding the overlay, but exposing a constant ConnectProgressViewModel all the time feels wrong when it’s only show occasionally.
The second seems to fit MVVM better with the ConnectProgressViewModel only being created when it’s needed, but it places more functionality onto the parent, and also the generic Overlay property feels a bit weird too.
Cheers
EDIT:
I should clarify that this view does more than just show busy status. It allows cancelling/retries and selection of different network resources etc. I omitted such details for brevity which was perhaps a mistake as people are concentrating on the busy indicator.
I always just use a
BusyIndicatorfrom the Silverlight Toolkit. It does not have a cancel button, but you can probably style it to have one. TheBusyIndicatorhas anIsBusyproperty that I bind to anIsBusyproperty on my ViewModel. If you style the control to have a button, you can add a cancel command to your ViewModel.Edit
I just saw that this is WPF not Silverlight. I’m not sure if the WPF Toolkit has a BusyIndicator
Edit Again
It looks like the Extended WPF Toolkit has a BusyIndicator. Note, I have no experience with this.