Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons looks disabled until I click something

Tags:

c#

wpf

I have a button bound to a ICommand

<Button Content="Remove" Command="{Binding RemoveCommand}" x:Name="btnRemove" Visibility="Collapsed" />

After some tasks is done, I made the button visible, except that they look disabled until I click something, why is that? The RemoveCommand looks like below

public ICommand RemoveCommand
{
    get
    {
        if (_removeCommand == null)
        {
            _removeCommand = new RelayCommand(() =>
            {
                if (RemoveRequested != null)
                    RemoveRequested(this, EventArgs.Empty);
            }, () =>
            {
                // CanExecute Callback
                if (Status == WorkStatus.Processing || Status == WorkStatus.Pending)
                {
                    Debug.WriteLine("Returning False" + Status); return false;
                }
                Debug.WriteLine("Returning True"); return true; // After uploads, this returns True, in my Output Window. 
            });
        }
        return _removeCommand;
    }

after uploads, the CanExecute callback returns True, so button should be enabled, but it looks disabled till I click something, why is this happening?

Video of the Problem

like image 993
Jiew Meng Avatar asked Nov 29 '10 10:11

Jiew Meng


1 Answers

Try CommandManager.InvalidateRequerySuggested().

This method should call the CanExecute() on the commands and that should update the IsEnabled of your buttons.

See http://msdn.microsoft.com/en-us/library/system.windows.input.commandmanager.invalidaterequerysuggested.aspx for more information.

like image 163
Pieter van Ginkel Avatar answered Sep 20 '22 20:09

Pieter van Ginkel