Binding to ViewModel does not work

Ribbon for WPF Forum

Posted 10 years ago by David Freer
Version: 9.1.0505
Avatar
I am trying to Bind Button state and Command Action to a ViewModel associated with a document window. When the active Document changes I set the DataContext of the desired Group, which then progates to it's buttons. The command bound in the XAML executes correctly, but the Button appears to only read the Enabled Property state; however, clicking the button does not invoke the setter on the viewmodel property. How can this be accomplished?

<ribbon:Group Label="Component" x:Name="componentGroup">
<ribbon:Button Command="{Binding TestCommand}"
ImageSourceSmall="pack://application:,,,/ActiproSoftware.Ribbon.Wpf30;component/ Products/Ribbon/Images/ButtonDefault32.png" Label="New Button" />
<ribbon:Button IsChecked="{Binding Enabled}"
ImageSourceSmall="pack://application:,,,/ActiproSoftware.Ribbon.Wpf30;component/ Products/Ribbon/Images/ButtonDefault32.png" Label="New Button" />

I set the Group DataContext when a Document becomes active

componentGroup.DataContext = _control.ViewModel;

My ViewModel (implements INotifyPropertyChanged) has the following Property and DelegateCommand

private bool _Enabled;
public bool Enabled
{
get { return this._Enabled; }

set
{
if (this._Enabled == value)
return;
this._Enabled = value;
OnPropertyChanged(() => Enabled);
}
}

DelegateCommand _TestCommand;
public DelegateCommand TestCommand
{
get
{
if (_TestCommand == null)
_TestCommand = new DelegateCommand(Test, CanTest);
return _TestCommand;
}
}

public bool CanTest()
{
return _canTestIt;
}

public void Test()
{
}

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

Right now the ribbon:Button is only intended to be checked via commands and through the use of the ICheckableCommandParameter interface. There is some documentation on that in the Command Model section and we show some examples in the samples.

The IsChecked property will not auto-toggle unless you use that mechanism and use the ICheckableCommandParameter to tell the button whether to toggle.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) 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.