DelegateCommand executed despite its isActive property is false

Aug 20, 2008 at 9:09 AM
Edited Aug 20, 2008 at 9:10 AM
Here is the pseudo code:

In my presenter, I have:

public DelegateCommand<object> RefreshCommand { get; private set; }
this.RefreshCommand = new DelegateCommand<object>(OnRefresh, OnCanExecuteOnRefresh);
           
RefreshCommand.IsActive = View.IsActive;
View.IsActiveChanged += view_IsActiveChanged;

private void OnRefresh(object parameter)
{
    PopulatePresentationModel();//do something
}

void view_IsActiveChanged(object sender, EventArgs e)
{
    RefreshCommand.IsActive = View.IsActive;
}

// unneccessary overhead?
private bool OnCanExecuteOnRefresh(object parameter)
{
    return RefreshCommand.IsActive;
}

Is that correct behavior or I am missing something?

Thanks in advance, Sanjin
Aug 21, 2008 at 3:58 AM
Hi Smatusan,  I believe my recent response in the following message thread: Commanding Problem on ListView Context Menu. will address your question.  If not let us know (perhaps with an example as Hulk did).  Note: I believe the issue may be that you are not executing RefreshCommand.RaiseCanExecuteChanged() as a result OnCanExecuteOnRefresh() only fires once and maintains the initial value.