[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]ViewModels
  [Expand]Commands
  [Collapse]Behaviors
    Getting Started
   [Collapse]Predefined Set
     EventToCommand
     KeyToCommand
     FocusBehavior
     ValidationErrorsHostBehavior
     ConfirmationBehavior
     DependencyPropertyBehavior
     EnumItemsSourceBehavior
     CompositeCommandBehavior
     FunctionBindingBehavior
     MethodToCommandBehavior
     CurrentWindowSerializationBehavior
     BarSubItemThemeSelectorBehavior
     BarSplitItemThemeSelectorBehavior
     RibbonGalleryThemeSelectorBehavior
    How to: Create a Custom Behavior
  [Expand]Services
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

FunctionBindingBehavior

The FunctionBindingBehavior class is a special behavior that allows you to bind the function result to your View.

Expanded Getting Started

Suppose that you have a function in your View Model that filters some collection, and you want to bind the function result to your View.

Below is a code snippet of ViewModel.

To bind the View's ChartControl and ViewModel's GetFilteredItems function, use the FunctionBindingBehavior. For this, add the behavior to the ChartControl's dxmvvm:Interaction.Behaviors collection.

Specify the FunctionBindingBehavior's properties in their corresponding order.

  • The Target property contains an object whose property will be populated (by default, the target-object is the behavior's associated object). Since the ChartControl shows data in a series, the ChartControl's Series FunnelSeries2D is used as Target.

  • The property of target-object should be specified using the Property property. The FunnelSeries2D shows data specified in the DataSource property. Thus, set Property to DataSource.

  • The Source property contains an object whose function will be bound to the target-property specified in Function (by default, the source-object is an object located in the data context of the associated object.). Due to the fact that the source-function is defined at the ViewModel level, bind the Source property to the ViewModel.

  • The source-function name is specified by the Function property.

  • The FunctionBindingBehavior also provides several properties that correspond to the source-function parameters: Arg1, Arg2... Arg15. You can specify no more than 15 arguments.

Expanded Invoking the Bound Function

By default, the FunctionBindingBehavior automatically re-invokes the Function when one of the arguments is changed (updated). If you need to manually re-invoke the Function, you can use the POCOViewModelExtensions.UpdateFunctionBinding extension method.

Below is a code snippet that illustrates how to use the UpdateFunctionBinding method.

Expanded Arguments Conversion

The FunctionBindingBehavior automatically converts its specified arguments to the parameterized type, if possible. Suppose that you have the following source-function in your View Model.

In this case, the parameter specified in the Arg1 property will be automatically converted to the DocumentType parameterized type.

Expanded Declaration by Using SmartTag

To assign the FunctionBindingBehavior to the required control at design time, click the Smart Tag button at the top right corner of the control.

Open the MVVM tab and add the FunctionBindingBehavior item using the Add Behavior menu.

Specify the Target (by default, it is the behavior's associated object).

Choose the target's property from the drop-down list.

Select the source object (by default, the source object is the DataContext of the target object) and the function of the source object, and specify its arguments. Smart Tag will generate argument property lines depending on the maximum number of the chosen function parameters. The maximum number of argument property lines is 15.

The following screenshot demonstrates the result.

The auto generated XAML for the above is the following.

Expanded Example

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T197048.

Is this topic helpful?​​​​​​​