Skip to main content
A newer version of this page is available. .

Functions and Parameters

  • 4 minutes to read

As described in Basic Principles, carousel works by binding item elements to Parameters, which are actually functions that take a position on a path as an argument. This mechanism is very flexible, because any representation aspect can be animated. In addition to flexibility, it is powerful and easy to use, because the resulting function can be a combination of three. This topic describes function types used in Carousel controls, and provides information on how they are combined to obtain the resulting function value at each path point.

Function Basics

Functions are FunctionBase descendants. This class provides a single public method (FunctionBase.GetValue) that accepts an argument and should return the bound property’s value. Parameter values range from 0 to 1. Function values depend on the bound property type. For instance, if you need to change element opacity, you’ll need to provide values between 0 and 255. If you’ll need to customize more complex data structures, say colors, you’ll need to use type converters when binding your properties. For an example, review the Conditional Item Parameters tutorial shipped with DXCarousel.

DXCarousel provides several built-in functions that you can use in your applications.

Function Class Description
EqualFunction Returns the argument.
LinearFunction A linear function in form of “K * Argument + B”. K and B values can be specified using the corresponding properties of the LinearFunction class.
SquareFunction Returns the square of the argument.
SineFunction Allows you to emulate sine curves. The function returns “A * Sin (Argument * W)”. You can specify the coefficients via the corresponding properties.
ZeroFunction Always returns zero.
ConstantFunction Always returns the same constant value specified via the Constant property.

If you want to declare a custom function, derive from FunctionBase and override its GetValueOverride method, called by FunctionBase.GetValue. See Lesson 4 - Using Functions and Parameters for an example.

Distribution Function

When you create a Parameter, its Distribution function is specified by the Parameter.DistributionFunction property. This function’s argument changes from 0 to 1, where 0 is the starting point and 1 is the ending point of the path. For instance, if you want the element in the middle to be the biggest, provide a function that returns small values for boundary arguments, and gradually increase the result when the argument approaches 0.5.

Using Distribution Functions, you can control element settings depending on their position along the path. You can also provide non-uniform element positioning using the same technique. To see an example, see the Item Distribution tutorial shipped with DXCarousel.

Transition Animation Functions

When the carousel is scrolled, its items move from one static position to another. Animation Transition Functions are created to provide control over these movements. Their arguments also change from 0 to 1, 0 being the starting point of a transition and 1 being the ending point. For examples of effects based on these functions, see the Animation Effects demo shipped with DXCarousel.

You can specify two functions for animation transitions - using the Parameter.AnimationAddFunction and Parameter.AnimationMulFunction properties. See the following section for information on how they influence the resulting bound property value.

Note

If you scroll the view by multiple items (e.g. by page), Transition Animation is applied only once.

Function Combination

As described above - for each property value you can specify three functions - one Distribution Function and two Transition Animation Functions. For each element position along the path, DXCarousel also calculates its position within the transition (if it’s in progress). The resulting property value is calculated using the following formula.

Property Value = Distribution Function (position) * Animation Multiplier Function (transition position) + Animation Additional Function (transition position)

As you see, using transition animations you can both modify the distribution value by providing a coefficient, or by adding/subtracting from its value. Obviously, some of these functions can return 0 or 1, so as not to affect the result, if you don’t need them.