Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Prevent a button from being clicked repeatably

$
0
0
Bladewise,
Thanks for the reply. That's what I thought and I previously tried something very similar to what you posted. Based on your code, I've implemented the following
private bool isBusy = false;

public bool IsBusy
{
    get { return isBusy; }
    set
    {
        if (isBusy != value) {
            isBusy = value;
            NotifyOfPropertyChange(() => IsBusy);
            NotifyOfPropertyChange(() => CanRequestData);
        }
    }
}

public bool CanRequestData
{
    get
    {
         return !IsBusy && AccountViewModel.Accounts.Count > 0;
    }
}

public void RequestData()
{
    if (!IsBusy) {
        try {
            IsBusy = true;
            ... // Perform the action ...            
        }
        finally {
            IsBusy = false;
        }
    }
}
This doesn't seem to disable the button whilst the action is taking place and the clicks are simply queued up. Do I need to use RaisePropertyChanged, because I couldn't find this method on my VM which is inheriting from Screen.

Regards
Alan

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>