views:

38

answers:

2

Hi, I hope someone can help me with this one...

Unfortunately to put all the code in is just not feasible, however.. I am implementing the MVVM pattern, I have a content presenter that displays a UserControl.

The UserControl has a number of items on it with some basic CRUD functions, e.g. Edit, Delete, etc.

I have set up the Control, so that the commands can only be enabled when an item is selected. e.g.

/// <summary>
/// Returns a command that makes a new Invoice
/// </summary>
public ICommand CommandViewInvoice
{
    get
    {
        if (_commandViewInvoice == null)
        {
            _commandViewInvoice = new DelegateCommand(ViewInvoice, CanCommandViewInvoice);
        }
        return _commandViewInvoice;
    }
}

However, for some reason sometimes the command is enabled, and sometimes it isnt - even though I am viewing exaclty the same items, and nothing has changed. In fact, if I just go in and out of the view 10 times, 9 out of ten times it will work correctly, but "sometimes" it just wont be enabled.

I cannot find a way to consistently replicate the error... it just sometimes happens and sometimes doesnt.

If anyone has come across a similar error, or has any useful suggestions on how I can make sure that these commands function correctly, or how I can debug this one, you will have my utmost gratitude...

A: 

Could you please post your CanCommandViewInvoice method? We'll need to see it to determine what is making it change.

Brent
Thanks Brent... What I found with the CanCommandViewInvoice function was that it had some pretty intensive query going in it.. so I started to stress test it. Basically, if I made it just loop for 10 000 cycles and then return true, the error would occur moe frequently? So I am assuming that there is something buggy about my approach, and so just reworked the solution to get round this.. Still not sure why this was occuring... but atleast it isnt a problem now.
Mark Pearl
A: 

If found this blog post to discuss a possible cause for this error

Mark Pearl