One of the features we've worked on for the v3.0 release is the
Behaviour API. We've listened to your feature requests and
the chart now supports a whole new range of inputs. This blog
post describes some of the new functionality and how it works
out-of-the-box as well as how to customise it to your needs.
We've also included an example chart demonstrating what is now
The new behaviour features we've added in 3.0 include:
- Events received from all mouse buttons, not just the left
- Actions performed on the axes are now also handled
- Modifier keys can be used to activate or disable
- Hot keys can also be used to switch behaviours on and off
- Behaviours can be operated through key presses
- Touch gesture input is supported
A number of the behaviours make use of this added functionality
out-of-the-box and they can also be easily customised. To do
that, it's helpful to know a little more about how the IBehaviour
interface now works.
The various actions that an IBehaviour can perform in response
to user input are now specified by methods with two parameters - a
sender and a context.
void PointerPressed(IBehaviourEventSource sender, PointerEventContext context);
The sender is typically the element from which the event
originated and the context contains information about the
event. You have control over which contexts are acted upon
(with the BehaviourActivator DP) and which senders can send
contexts to the behaviour (with the AcceptedSources DP). The
next two sections will look at what you can do with each of
You can use this property to restrict a behaviour to only act on
input from, for example, the XAxis or any given axis or just from
the plot area. There's a lot of flexibility in the restrictions you
can place and if there's a new sort of condition you'd like to have
you can implement the simple IEventSourceCondition.
The provided IEventSourceConditions are:
- SpecificTypeEventSource - this can limit
interaction to the plot area or any one of the axis containers
- SpecificInstanceEventSource - this mean events
are only accepted from a given instance, which will be an
- AnyEventSource - this one let's you plug
together a number of conditions and accept the event if the source
meets any one of your conditions
- All axes themselves also implement IEventSourceCondition so you
can also simply assign an axis to the AcceptedSources
This property allows you to say which event contexts should be
accepted. The property is of type IBehaviourActivator, which
just has an AcceptEvent method. Again, a number of
IBehaviourActivators are provided, as well as a type converter,
making it easy to specify this property in xaml.
- PointerBehaviourActivator - used to control
actions on the button pressed, mouse wheel scrolling or
position. Also let's you restrict based on any modifier keys
that might be held.
- ModifierBehaviourActivator - activates a
behaviour if any combination of modifier keys is held
- PinchBehaviourActivator and
DragBehaviourActivator can be used to manipuate
behaviours with gesture input.
- The AllConditionsBehaviourActivator and
AnyConditionsBehaviourActivator are used to
combine conditions - they accept an event if all
of their child activators or any of their child
activators would accept that event, respectively.
Finally a note on keyboard input - this is handled with the
KeyDown and KeyUp methods on IBehaviour. Key presses don't
have a sender, so the methods take only a KeyEventContext, which
contains information on the key pressed, and any modifier
Here's an example that pulls those ideas together into one
chart. The chart let's you:
- Zoom with the left button and pan with the right button
- Have crosshairs appear only when the mouse is over axes
- Trackballs only operate when the Ctrl key is held
We've also added DiagnosticBehaviour, which polls each of the
other behaviours handled in the Chart's BehaviourManager to see if
the events it is receiving would be accepted by other
behaviours. The DiagnosticBehaviour maintains the explanatory
text below the chart.
The source code for this example can be downloaded here -
you'll need to drop in a Visiblox Charts dll, either purchased or
from your trial to be able to compile it.