Those of you who've upgraded to 3.0 may have noticed a change in
the way ContextMenus work. Since the new Behaviour API now
subscribes to right mouse button clicks. those events are now
considered to be handled and so any ContextMenus that may have been
set don't open.
The way to get ContextMenus working in 3.0 is to write a
Behaviour that will open the menu when the right button is
clicked. We've included an example of a behaviour that will
do this - it's really simple and the main methods in a WPF version
of such a class are given below:
public override void PointerPressed(IBehaviourEventSource sender, PointerEventContext context)
{
if (Menu != null)
{
sender.BehaviourCanvas.CaptureMouse();
Menu.PlacementTarget = BehaviourCanvas;
Menu.IsOpen = true;
}
}
public override void PointerReleased(IBehaviourEventSource sender, PointerEventContext context)
{
if (Menu != null)
{
Menu.IsOpen = false;
sender.BehaviourCanvas.ReleaseMouseCapture();
}
}
protected override void Init()
{
BehaviourCanvas.ContextMenu = Menu;
}
public override void DeInit()
{
if (Menu != null)
{
Menu.IsOpen = false;
}
}
The only other piece of the puzzle is to make sure that this new
ContextMenuBehaviour is only activated by right mouse button.
You can do that via the new BehaviourActivator property on
our behaviours. Just set that to "RightMouse" in XAML or
attache a PointerButtonBehaviourActivator in code behind.
And there it is, ContextMenu support for Visiblox Charts
3.0.
You can download source code for an example WPF application here - you'll
need to drop in a Visiblox Charts dll, either purchased or from
your trial to be able to compile it. Please note this
approach requires Visiblox Charts 3.0.1 or later to work
correctly.