My prism application has a lot of async operations called from my view models. In some cases, I want the view to be disabled and display some kind of busy indicator until the viewmodel gets back the result from the async operation.
I though of creating a base view which will implement this behavior (i.e have a dependency property of IsLoading which will disable the view and display a busy indicator above it). The problem is, I'm not sure how to implement this base view. Any help would be appreciated, thanks.
Edit: I wrote a LoadingView which does the job, I think.
public class LoadingView : UserControl
{
private object content;
public bool IsLoading
{
get
{
return (bool)GetValue(IsLoadingProperty);
}
set
{
SetValue(IsLoadingProperty, value);
}
}
private ProgressRing m_RingControl;
public LoadingView()
{
m_RingControl = new ProgressRing();
m_RingControl.IsActive = false;
}
// Using a DependencyProperty as the backing store for IsLoading. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsLoadingProperty =
DependencyProperty.Register("IsLoading", typeof(bool), typeof(LoadingView), new PropertyMetadata(false, IsActivePropertyChanged));
private static void IsActivePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
LoadingView view = d as LoadingView;
if (view != null)
{
// Loading - show ring control
if (((bool)e.NewValue) == true)
{
view.content = view.Content;
view.Content = view.m_RingControl;
view.m_RingControl.IsActive = true;
}
else
{
view.m_RingControl.IsActive = false;
view.Content = view.content;
}
}
}
}
and i put binding on LoadingView.IsLoading with some IsLoading (or IsBusy) in the viewmodel