1

The scenario is that I have text box which I put there URL when the user

type the url and press go I call to the service in TPL ,when the service

is loaded I need to enable the next button(Im working on wizard) if I dont use TPL IsServicevalid get true(bind to command)and the next button is enabled .but in task(TPL) the data is loaded and the next is disabled (even if I put it in the continue) I have noticed that if I click on the page with the mouse anywhere the next turn to enable,do you face some issue like this before?

even if the next button is disabled and I click on it it turn to enable ,all of this happen

just when I use task ,any idea?

this is strange ...:(

Task.Factory
    .StartNew(() =>
    {
        //-----get service Data ---------
        try
        {
            GetUsersData();
        }
        catch (Exception e)
        {
            _isValid = false;
            ThrowErrorMessage(e.Message);
        }
    })
    .ContinueWith((task) =>
    {
        Mouse.OverrideCursor = null;
    }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());

    isServiceValid = true;
2
  • 1
    I see this "command can execute not updating" problem very often, even in non task related activities. Calling System.Windows.Input.CommandManager.InvalidateRequerySuggested() seems to fix it most of the time (i guess that's what is called when you click the ui and it suddenly updates). Commented Feb 25, 2014 at 10:30
  • @Dtex- thank you very much !!! propose it as answer Commented Feb 25, 2014 at 10:39

1 Answer 1

2

Sometimes the CanExecute state of commands won't be reflected on the ui untill you click on it.

I don't know why this happens, I personally think this is a behavior that should be changed in the framework itself if possible.

However you can force an update by calling

System.Windows.Input.CommandManager.InvalidateRequerySuggested();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Dtex,Just to verify what do you mean fix in the framework?
I mean that ideally we should not have to call this method directly, but life isn't always ideal :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.