Ribbon Button state not updated when bound to a DelegateCommand

Ribbon for WPF Forum

Posted 6 years ago by Ed Starkey
Version: 12.1.0562
Avatar

I use your ribbon buttons to perform several actions, all of which are bound using the buttons Command parameter to a DelegateCommand property in my ViewModel. Application logic may enable and disable the canExecute parameter of the DelegateCommand, but the button enable state does not change. I am also firing a PropertyChanged event whenever enable/disable logic changes occur so they can propogate to the View, but this has no effect.

If I hide and then show the ribbion bar, I found that the changes were pushed out to the view properly. Why doesn't onPropertyChange events modify the enable state of the ribbon:button automatically?

At one point in the project, we were using the application button, and everything worked fine (or so I thought). It seems that what was really happening, is that when the app button was clicked on, then the underlying button states were updated.

 

<ribbon:Button x:Name="saveTestButton" Label="Save Test" KeyTipAccessText="S" Command="{Binding Path=SaveTest}"/>

 

private DelegateCommand saveTest;
private bool saveTestEnabled = false;
...

public DelegateCommand SaveTest
{
     get
     {
         return saveTest;
     }

     set
     {
         saveTest = value;
         onPropertyChanged("SaveTest");
     }
}       
...

saveTest = new  DelegateCommand(SaveTestAction, canSaveTestAction);

private bool canSaveTestAction()
{
    return saveTestEnabled;
}

private void SaveTestAction()
{
       //Save test stuff...
}

 private void onPropertyChanged(string propertyChanged)
{
      if (PropertyChanged != null)
      {
           PropertyChanged(this,new PropertyChangedEventArgs(propertyChanged));
      }
}

Comments (2)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ed,

Commands use the ICommand.CanExecuteChanged event to notify controls when their CanExecute state has changed.  So you need to raise that event on your command.  Raising PropertyChanged events won't do any good for existing commands that are already bound to.


Actipro Software Support

Posted 6 years ago by Ed Starkey
Avatar

That took care of it, thanks!

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.