Skip to main content

FunctionBindingBehavior Class

Binds a ViewModel function’s result to a control’s property.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v23.2.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public class FunctionBindingBehavior :
    FunctionBindingBehaviorBase

Remarks

Specify the following FunctionBindingBehavior properties to bind a ViewModel function’s result to a property of a control in a View:

Target

An object whose Property value should be changed to the bound function‘s result. The default target object is the behavior’s associated object.

In the code sample below, the ChartControl’s FunnelSeries2D series is used as Target.

Property

A Target object’s property name. When the Function is executed, its result changes the specified property’s value.

In the code sample below, the FunnelSeries2D shows data specified in the DataSource property.

Source

An object whose Function‘s result should change the Target object’s Property. The default source object is an object from the associated object’s data context.

In the code sample below, the source function is defined in the ViewModel (the Source property is bound to the ViewModel).

Function

A name of a Source‘s function whose result should change the Target‘s Property value.

In the code sample below, the Function is set to the GetFilteredItems function from the bound ViewModel.

Arg* Properties

A View’s properties that the behavior should pass to the Function as arguments. You can specify up to 15 arguments.

The FunctionBindingBehavior converts the specified arguments to the parameterized type, if possible.

In the code sample below, the FunctionBindingBehavior passes the range control’s SelectionRangeStart and SelectionRangeEnd properties to the target function as arguments.

The following figure illustrates the FunctionBindingBehavior‘s properties structure:

DevExpress MVVM Behaviors | FunctionBindingBehavior Anatomy

The following code sample binds the ChartControl to a ViewModel’s GetFilteredItems function and passes the RangeControl‘s SelectionRangeStart and SelectionRangeEnd properties:

<dxc:ChartControl ... >
    <dxc:ChartControl.Diagram>
        <dxc:SimpleDiagram2D>
            <dxc:SimpleDiagram2D.Series>
                <dxc:FunnelSeries2D x:Name="Series" ... >
                    ...
                </dxc:FunnelSeries2D>
            </dxc:SimpleDiagram2D.Series>
        </dxc:SimpleDiagram2D>
    </dxc:ChartControl.Diagram>
    ...
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:FunctionBindingBehavior Target="{Binding ElementName=Series}"       
                                        Property="DataSource" 
                                        Source="{Binding}"
                                        Function="GetFilteredItems" 
                                        Arg1="{Binding SelectionRangeStart, ElementName=rangeControl}" 
                                        Arg2="{Binding SelectionRangeEnd, ElementName=rangeControl}"/>
        </dxmvvm:Interaction.Behaviors>
</dxc:ChartControl>
<dxe:RangeControl Name="rangeControl" SelectionRangeStart="1/1/2015" SelectionRangeEnd="7/1/2015">
    <!-- ... -->
</dxe:RangeControl>
public class MainViewModel {
    protected MainViewModel() { ... }

    public static MainViewModel Create() {
        return ViewModelSource.Create(()=>new MainViewModel());
    }

    public virtual ObservableCollection<DataItem> Points { get; set; }

    public IList<DataItem> GetFilteredItems(DateTime start, DateTime end) {
        return this.Points.Where(x => x.Date.Date >= start && x.Date.Date <= end).ToList();
    }
}

View Example: How to Use FunctionBindingBehavior

Re-Invoke a Function

The FunctionBindingBehavior re-invokes the specified Function when one of its arguments is changed.

You can execute the POCOViewModelExtensions.UpdateFunctionBinding extension method to re-invoke the GetFilteredItems function:

public class MainViewModel {
    ...
    public void Update() {
        this.UpdateFunctionBinding(x => x.GetFilteredItems(default(DateTime), default(DateTime)));
    }
}

Inheritance

Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<DependencyObject>
FunctionBindingBehaviorBase
FunctionBindingBehavior
See Also