Click or drag to resize
weroSoft AG, Software
InvokeCommandBehavior Class
The documentation is integral part of the weroSoft product documentation. This part is intended to be used by developers only.
This behavior allows connecting a event of a control with a command.
Inheritance Hierarchy
SystemObject
  System.Windows.ThreadingDispatcherObject
    System.WindowsDependencyObject
      System.WindowsFreezable
        System.Windows.Media.AnimationAnimatable
          Behavior
            BehaviorFrameworkElement
              WeroSoft.Windows.ControlsInvokeCommandBehavior

Namespace:  WeroSoft.Windows.Controls
Assembly:  WeroSoft.Client.Desktop.Library (in WeroSoft.Client.Desktop.Library.dll) Version: 3.0 Pre-Release
Syntax
C#
public class InvokeCommandBehavior : Behavior<FrameworkElement>
Remarks

The WPF is built to bind commands to controls implementing the ICommandSource interface. This interface provides the popular Command and CommandParameter properties. The MVVM pattern targets the goal that no code behind is written in a view. Unfortunately this is not easy if events are used in the controls because events are not routed to commands because the command source dos not support this behavior.

This type provides a solution for this dilemma. It implements a framework behavior which allows connecting the event raising with a command execution by registering a behavior to the appropriate control using the interaction interface of the WPF.

Examples

This sample demonstrates the registration of the behavior in the XAML (first code samples). The sample assumes that the used view model provides the appropriate command, whose code is shown as second part.

The sample uses the following XML name spaces in XAML code definition:

XML name spaceDefinition
viewhttp://schemas.weroSoft.net/xaml/controls
ihttp://schemas.microsoft.com/expression/2010/interactivity
wschttp://schemas.weroSoft.net/xaml/controls

XAML Code
  <GroupBox Grid.Row="1" Header="Sliding pages">
    <view:SlidingPageControl Grid.Row="4" Grid.ColumnSpan="6"
                             Name="SlidingPageControl"
                             ObjectCollection="{Binding SlidingPageCollection, Mode=TwoWay}"
                             DefaultScrollMode="{Binding DefaultScrollMode}"
                             CustomConfiguration="{Binding TestConfiguration}"
                             SlidingPageHiddenAction="SlidingPageHiddenAction"
                             SlidingPageLoadedAction="SlidingPageLoadedAction"
                             SlidingPageShownAction="SlidingPageShownAction"
                             SlidingPageUnloadedAction="SlidingPageUnloadedAction" >
        <i:Interaction.Behaviors>
            <wsc:InvokeCommandBehavior Event="SlidingPageValidateAction"
                                       Command="{Binding SlidingPageValidateCommand}"
                                       PassArguments="True" />
        </i:Interaction.Behaviors>
    </view:SlidingPageControl>
</GroupBox>

Command implementation
public class SlidingPageValidateCommand : ICommand
{
    public event EventHandler CanExecuteChanged = delegate { };

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public void Execute(object parameter)
    {
        // Check whether the parameter has the correct type to access the
        // needed information.
        if (parameter is EventArgsWrapper wrapper && 
            wrapper.EventArgs is SlidingPageValidateEventArgs slidingPageEventArgs)
        {
            // Get the view model of the sender.
            SlidingPageDialogViewModel viewModel = wrapper.GetSenderViewModel<SlidingPageDialogViewModel>();

            // Add your decision code here.
            // ...
            if (viewModel.DisablePageChange)
            {
                // If changing the sliding page shall be avoided,
                // set the cancel event here.
                slidingPageEventArgs.Cancel = true;
            }
        }
    }
}

The InvokeCommandBehavior type exposes the following members.

Constructors
  NameDescription
Public methodInvokeCommandBehavior
Initializes a new instance of the InvokeCommandBehavior class
Top
Properties
  NameDescription
Protected propertyAssociatedObject (Inherited from BehaviorFrameworkElement.)
Protected propertyAssociatedType (Inherited from Behavior.)
Public propertyCanFreeze
Gets a value that indicates whether the object can be made unmodifiable.
(Inherited from Freezable.)
Public propertyCommand
Gets or sets the command to execute.
Public propertyDependencyObjectType
Gets the DependencyObjectType that wraps the CLR type of this instance. 
(Inherited from DependencyObject.)
Public propertyDispatcher
Gets the Dispatcher this DispatcherObject is associated with.
(Inherited from DispatcherObject.)
Public propertyEvent
Gets or sets the event to handle.
Public propertyHasAnimatedProperties
Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties.
(Inherited from Animatable.)
Public propertyIsFrozen
Gets a value that indicates whether the object is currently modifiable.
(Inherited from Freezable.)
Public propertyIsSealed
Gets a value that indicates whether this instance is currently sealed (read-only).
(Inherited from DependencyObject.)
Public propertyPassArguments
Gets or sets whether the arguments shall be passed to the command or not.
Public propertySender
Gets or sets the sender of the action.
Top
Methods
  NameDescription
Public methodApplyAnimationClock(DependencyProperty, AnimationClock)
Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used.
(Inherited from Animatable.)
Public methodApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)
Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used.
(Inherited from Animatable.)
Public methodAttach (Inherited from Behavior.)
Public methodBeginAnimation(DependencyProperty, AnimationTimeline)
Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used.
(Inherited from Animatable.)
Public methodBeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)
Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used.
(Inherited from Animatable.)
Public methodClearValue(DependencyProperty)
Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.
(Inherited from DependencyObject.)
Public methodClearValue(DependencyPropertyKey)
Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.
(Inherited from DependencyObject.)
Public methodClone
Creates a modifiable clone of this Animatable, making deep copies of this object's values. When copying this object's dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values.
(Inherited from Animatable.)
Protected methodCloneCore
Makes the instance a clone (deep copy) of the specified Freezable using base (non-animated) property values.
(Inherited from Freezable.)
Public methodCloneCurrentValue
Creates a modifiable clone (deep copy) of the Freezable using its current values.
(Inherited from Freezable.)
Protected methodCloneCurrentValueCore
Makes the instance a modifiable clone (deep copy) of the specified Freezable using current property values.
(Inherited from Freezable.)
Public methodCoerceValue
Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.
(Inherited from DependencyObject.)
Protected methodCreateInstance
Initializes a new instance of the Freezable class.
(Inherited from Freezable.)
Protected methodCreateInstanceCore (Inherited from Behavior.)
Public methodDetach (Inherited from Behavior.)
Public methodEquals
Determines whether a provided DependencyObject is equivalent to the current DependencyObject.
(Inherited from DependencyObject.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFreeze
Makes the current object unmodifiable and sets its IsFrozen property to true.
(Inherited from Freezable.)
Protected methodFreezeCore
Makes this Animatable object unmodifiable or determines whether it can be made unmodifiable.
(Inherited from Animatable.)
Public methodGetAnimationBaseValue
Returns the non-animated value of the specified DependencyProperty.
(Inherited from Animatable.)
Public methodGetAsFrozen
Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference.
(Inherited from Freezable.)
Protected methodGetAsFrozenCore
Makes the instance a frozen clone of the specified Freezable using base (non-animated) property values.
(Inherited from Freezable.)
Protected methodGetCommandParameter
Returns the parameter of the command.
Public methodGetCurrentValueAsFrozen
Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference.
(Inherited from Freezable.)
Protected methodGetCurrentValueAsFrozenCore
Makes the current instance a frozen clone of the specified Freezable. If the object has animated dependency properties, their current animated values are copied.
(Inherited from Freezable.)
Public methodGetHashCode
Gets a hash code for this DependencyObject.
(Inherited from DependencyObject.)
Public methodGetLocalValueEnumerator
Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.
(Inherited from DependencyObject.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValue
Returns the current effective value of a dependency property on this instance of a DependencyObject.
(Inherited from DependencyObject.)
Public methodInvalidateProperty
Re-evaluates the effective value for the specified dependency property
(Inherited from DependencyObject.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnAttached
Event handler on attaching the behavior to the control.
(Overrides Behavior.OnAttached.)
Protected methodOnChanged
Called when the current Freezable object is modified.
(Inherited from Freezable.)
Protected methodOnDetaching (Inherited from Behavior.)
Protected methodOnFreezablePropertyChanged(DependencyObject, DependencyObject)
Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.
(Inherited from Freezable.)
Protected methodOnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)
This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
(Inherited from Freezable.)
Protected methodOnPropertyChanged
Overrides the DependencyObject implementation of OnPropertyChanged(DependencyPropertyChangedEventArgs) to also invoke any Changed handlers in response to a changing dependency property of type Freezable.
(Inherited from Freezable.)
Public methodReadLocalValue
Returns the local value of a dependency property, if it exists.
(Inherited from DependencyObject.)
Protected methodReadPreamble
Ensures that the Freezable is being accessed from a valid thread. Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties.
(Inherited from Freezable.)
Public methodSetCurrentValue
Sets the value of a dependency property without changing its value source.
(Inherited from DependencyObject.)
Public methodSetValue(DependencyProperty, Object)
Sets the local value of a dependency property, specified by its dependency property identifier.
(Inherited from DependencyObject.)
Public methodSetValue(DependencyPropertyKey, Object)
Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.
(Inherited from DependencyObject.)
Protected methodShouldSerializeProperty
Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.
(Inherited from DependencyObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Protected methodWritePostscript
Raises the Changed event for the Freezable and invokes its OnChanged method. Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.
(Inherited from Freezable.)
Protected methodWritePreamble
Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties.
(Inherited from Freezable.)
Top
Events
  NameDescription
Public eventChanged
Occurs when the Freezable or an object it contains is modified.
(Inherited from Freezable.)
Top
Fields
  NameDescription
Public fieldStatic memberCommandProperty
The DependencyProperty of Command.
Public fieldStatic memberEventProperty
The DependencyProperty of Event.
Public fieldStatic memberPassArgumentsProperty
The DependencyProperty of PassArguments.
Public fieldStatic memberSenderProperty
The DependencyProperty of Sender.
Top
Extension Methods
  NameDescription
Public Extension MethodClone(CloneWorkingMode, IEnumerableType)Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.)
Public Extension MethodCloneT(CloneWorkingMode, IEnumerableType)Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.)
Public Extension MethodConvert (Defined by DataConverterExtensions.)
Public Extension MethodCreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String)Overloaded.
Creates a data entry into a string builder according to the giving parameters.
(Defined by TraceExtensions.)
Public Extension MethodCreateTraceDataEntry(SourceLevels, TraceableKind, String, String, Int32)Overloaded.
Creates a trace entry for a data element.
(Defined by TraceExtensions.)
Public Extension MethodCreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String, String, Int32)Overloaded.
Creates a trace entry into a string builder.
(Defined by TraceExtensions.)
Public Extension MethodDynamicCast
Dynamically casts a reference to another type.
(Defined by TypeManagerHelper.)
Public Extension MethodExtractSystemParametersFromTrigger
Extracts the system parameters from a collection of trigger parameter and transform them to a dictionary using string keys and string values.
(Defined by TriggerExtensions.)
Public Extension MethodGetFieldValue(String)Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetFieldValueT(String)Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetParentDependencyObjectOfType
Extension method for dependency objects to resolve a parent of a defined type.
(Defined by WindowsHelper.)
Public Extension MethodGetPropertyValue(String)Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetPropertyValueT(String)Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodInject(Type, Object)Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.)
Public Extension MethodInject(Type, Object, Boolean)Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.)
Public Extension MethodInjectField
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInjectProperty(String, Object)Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInjectProperty(String, Type, Object)Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInvoke(String, Object)Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.)
Public Extension MethodInvokeTResult(String, Object)Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.)
Public Extension MethodSetFieldValue
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodSetPropertyValue
Sets the data object on a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodSetReadOnlyFieldValue
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodTryInjectProperty
Tries to Inject a value to a property within a data object.
(Defined by DataInjection.)
Top
See Also