This project has moved and is read-only. For the latest updates, please go here.

BusyIndicator for a button using MVVM

Nov 3, 2010 at 4:38 PM
Edited Nov 3, 2010 at 5:13 PM

Is there Anyway of starting the busy indicator on a button click. I am using commands with MVVM so what I want to do is on my execute of the button processing I want to set the IsBusy property that is bound to the IsBusy indcator on the control to true then do my processing at the end set it back to false.  I have it set up but the indicator never comes up?  I working in VB.NET.

Nov 3, 2010 at 4:47 PM

Sounds like you are doing it right.  Make sure your IsBusy property fires the PropertyChanged event.  Does your VM class implement the INotifyProperyChanged interface?

Nov 3, 2010 at 5:24 PM

I set the property to true on the button click to make sure I had everything properly pointed in the Xaml.  When I click the button the progress indicator comes up and stays there so I need to some how get it to go off and run my process async.  I am investigating on how to run a background worker. That may work hopefully.


Nov 3, 2010 at 5:33 PM
Edited Nov 3, 2010 at 5:33 PM

try this in your ViewModel.

IsBusy = true;

BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += delegate(object sender, DoWorkEventArgs e)
     //do work
worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
     IsBusy = false;

Nov 3, 2010 at 6:50 PM

Got it work but now have other issues updating an object on the UI thread but as for getting the progress indcator to work I am good to go. Here is the version just incase some one else needs the same thing.

 Private WithEvents bgWorker As New BackgroundWorker
Private Sub RefreshExecute(ByVal param As Models.NameModel)
            IsBusy = True


        End Sub

        Private Sub bgWorker_DoWork(ByVal sender As ObjectByVal e As System.ComponentModel.DoWorkEventArgsHandles bgWorker.DoWork
        End Sub
        Private Sub bgWorker_DoWork(ByVal sender As ObjectByVal e As System.ComponentModel.RunWorkerCompletedEventArgsHandles bgWorker.RunWorkerCompleted
            IsBusy = False
        End Sub