Problems with implementation of BarToggleButtonViewModel and CheckableCommandParameter

Bars for WPF Forum

The latest build of this product (v25.1.1) was released 2 months ago, which was before this thread was created.
Posted 4 days ago by Michael Foegelle
Version: 25.1.1
Platform: .NET 8
Environment: Windows 11 (64-bit)
Avatar

I'm building a GUI around the WPF Dockable Toolbars example using your view model library and attempting to replicate behavior I was able to produce in standard toolbars with simple bindings to a couple of type converters.  Since there's no direct (documented) IsChecked interface in the view model, I've ended up with a RelayCommand that implements a CanExecute check using a CheckableCommandParameter with code that is equivalent to that found at the following link: 

https://www.actiprosoftware.com/docs/controls/wpf/ribbon/command-model/checkable-controls

While the event fires properly and the enable behavior works as expected, the button just toggles its checked state on and off each time it's clicked, rather than paying any attention to the returned IsChecked state that it should be in.  Google's AI search just tells me that your components don't work as documented, but I figured I would check and see if there's something I'm missing and if there's a way to get the desired behavior.

On top of this, I need the toolbar to support multi-select button groups.  This was a standard feature in a competing library I used years ago, so I kind of expected this to be a no brainer here, but it's starting to look like binding IsChecked to my own converters in code behind or searching throught the controls for all of the related buttons in the Execute command are the only ways I'm going to get this to work.

Any thoughts before I go down the wrong path?

Thanks,

Michael

Comments (1)

Posted 4 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

With the Bars controls, including those for dockable toolbars, we went with a more standard command-based design like that found in other native WPF controls.  Whereas the older legacy Ribbon product that you referred to above (CheckableCommandParameter is part of that), did things with commands that were advanced but went far beyond what they "should" have been doing for proper MVVM design.  Thus the newer Bars product is not compatible with the concepts from that legacy Ribbon product.

When using MVVM to populate toggle controls in a docking toolbar, you'd use viewmodels behind the scenes like our BarToggleButtonViewModel class in our Bars MVVM library.  BarToggleButtonViewModel has a Command property that you can use to execute an action and determine the control's enabled state.  It also has a IsChecked property that gets bound to the related UI control's checked state.

Say you have a Bold button.  Its command should be a ToggleBoldCommand and the Execute method should toggle the viewmodel's IsChecked state.

In a more advanced scenario where you have a button group like for a text alignment set of buttons (left, center, right), you'd have a SetTextAlignmentCommand and the CommandParameter for each viewmodel should be set to some related alignment enum option.  The SetTextAlignmentCommand Execute logic should get the three viewmodels, and set the IsChecked property appropriately on each based on if the command parameter passed in matches.  That ensures that only one of the three is ever checked at a time.

By using viewmodels in this way, you can have UI for these viewmodels in toolbars, menus, etc. and they all will update live.

I hope that helps!


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.