Interaction with Value Controls
Some controls are associated with a value. TextBox, ComboBox, RibbonGallery, and PopupGallery, controls are good examples. For these, an IValueCommandParameter command parameter is assigned by default to the control.
Ribbon includes a generic implementation of IValueCommandParameter named ValueCommandParameter
. This class can be constructed using any type such as a string
, FontFamily
, etc. Ribbon has several built-in constructed types of IValueCommandParameter such as ObjectValueCommandParameter, DoubleValueCommandParameter, StringValueCommandParameter, BrushValueCommandParameter, and FontFamilyComboBox.
When the CanExecute
event of the command is handled in your code, set the Handled property of the parameter to true
and set the UpdatedValue property to the current value of the control. For instance, in a font family command CanExecute
handler, the UpdatedValue
would be set to Tahoma
if that was the current FontFamily
in use. The CanExecute
handler for value controls is nearly the same as for checkable controls except that you set the UpdatedValue property instead of IsChecked.
When the Execute
event of the command is handled in your code, the Action property indicates the current action (via an enum of type ValueCommandParameterAction), which can be Commit
, Preview
, or CancelPreview
. Commit
means use the value in the Value property and commit it to the selection.
Preview
and CancelPreview
are for controls that support live previewing (hovering over an item to see how selecting that item would change the selection). A great example is font family comboboxes where hovering over items shows how the selection updates to the new font family without really commiting the update until the font family is actually clicked. Preview
means to ensure the real state of the selection is backed up and to preview an updated selection based on the value in the PreviewValue property. CancelPreview
means to cancel preview mode and restore the backup of the real selection state. A Commit
issued during preview mode means to accept the preview as the new selection state.
Since the ribbon controls require the command's can-execute method logic to fire for updating of the value, it may be necessary to raise the command's CanExecuteChanged
event following a programmatic change that affects the new value, especially if the command is not a routed command.