Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Unregister LeftCntrl and LeftShift keys from Panning and Zooming to None

Hi,

 

I want to use the LeftCntrl and LeftShift keys for my own functions in the PlotArea, but it seems as though the default is set to using them to pan and zoom. Is there any way to change the default interaction for these keys?

 

Thanks

0 Kudos
Message 1 of 2
(2,265 Views)

Each interaction determines what modifier keys it supports (if any), so there is no direct way to change this and keep the interaction. However, the interactions available on the graph are controlled by the Interactions collection, so you can remove or modify this collection as needed. If you do not want any interactions, you can use <ni:Graph Interactions="" ...> in XAML, or assign a new collection in code (since the default collection is frozen).

 

If you want to keep the interactions, but limit which modifier key they support, you can wrap the interaction to add the additional filter. Here is an example class that only allows the RightCtrl and RightShift modifier keys:

 

public class RightModifierInteraction : GraphInteraction {
    private readonly GraphInteraction _interaction;

    public RightModifierInteraction( GraphInteraction interaction ) {
        this._interaction = interaction;
    }

    public override bool AcceptsModifier( ModifierKeys modifiers ) {
        // If the interaction does not use the modifier, return false.
        if( !this._interaction.AcceptsModifier( modifiers ) )
            return false;

        // Otherwise, determine if we are using the appropriate right-sided modifier.
        Key targetKey;
        switch( modifiers ) {
            case ModifierKeys.Control:
                targetKey = Key.RightCtrl;
                break;
            case ModifierKeys.Shift:
                targetKey = Key.RightShift;
                break;

            default:
                targetKey = Key.None;
                break;
        }

        return Keyboard.IsKeyDown( targetKey );
    }

    #region Pass-thru implementation

    public override string Name {
        get { return "Right" + this._interaction.Name; }
    }

    public override System.Windows.Input.Cursor ActiveCursor {
        get { return this._interaction.ActiveCursor; }
    }

    public override System.Windows.Input.Cursor Cursor {
        get { return this._interaction.Cursor; }
    }

    public override Orientation? Orientation {
        get { return this._interaction.Orientation; }
    }

    public override GraphInteractionTriggers Triggers {
        get { return this._interaction.Triggers; }
    }

    protected override int CompareParameters( EnumObject other ) {
        var target = other as RightModifierInteraction;
        return target == null ? 1 : this._interaction.CompareTo( target._interaction );
    }

    public override void Execute( IInteractiveGraph graph, GraphInteractionArgs args ) {
        this._interaction.Execute( graph, args );
    }

    #endregion
}

Assuming you want the default interactions, you could initialize your graph in code like so:

 

var interactions = new GraphInteractionCollection( );
foreach( var interaction in graph.Interactions ) {
    bool usesModifier =
           interaction.AcceptsModifier( ModifierKeys.Control )
        || interaction.AcceptsModifier( ModifierKeys.Shift );
    interactions.Add( usesModifier ? new RightModifierInteraction( interaction ) : interaction );
}

graph.Interactions = interactions;
~ Paul H
Message 2 of 2
(2,208 Views)