Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph control block Ctrl + grab and block DefaultInteraction PanHorizontal for negative value

Solved!
Go to solution

Hi it's my first post on the forum

I have a problem with NI graph control. 

 

I want to block but I don’t know how move graph under negative value, because it’s never exists on my case. I tried use PanHorizontal (DefaultInteraction) but I can move graph to negative value.

 

And my second problem with click Ctrl + grab graph. Then I can move my grap everyvhere and it’s very confusing for user. 

 

Sample in upload image.

 

How to block this?

Download All
0 Kudos
Message 1 of 3
(1,980 Views)
Solution
Accepted by topic author jk_bb8

As you have found, the built-in graph interactions only include limits for direction, not range. Although you could create a custom GraphInteraction to limit the range, it would be simpler to listen for range changes on the axis, and reset the range to stay within your limit:

 

XAML:

<ni:Graph DefaultInteraction="PanHorizontal" Interactions="PanHorizontal">
    <ni:Graph.Axes>
        <ni:AxisDouble Orientation="Horizontal" RangeChanged="OnHorizontalRangeChanged"/>
    </ni:Graph.Axes>
</ni:Graph>

Code:

private void OnHorizontalRangeChanged( object sender, ValueChangedEventArgs<Range<double>> e ) {
    var axis = (Axis<double>)sender;
    const double MinimumLimit = -0.5;
    if( e.NewValue.Minimum < MinimumLimit ) {
        double delta = e.NewValue.Maximum - e.NewValue.Minimum;
        axis.Range = new Range<double>( MinimumLimit, MinimumLimit + delta );
    }
}

The DefaultInteraction property determines what interaction (if any) can be performed without using keyboard modifiers. The Interactions collection determines which interactions can be performed by using keyboard modifiers. For example, if you set Interactions to include just PanHorizontal (instead of the default of both Pan and Zoom), then Ctrl+drag will be limited to horizontal panning.

~ Paul H
Message 2 of 3
(1,958 Views)

Thx from solution with samples. Your solution partly solved my problem, I can write the rest. I'm happy with the effect. 

I have a lot of question but in other thread

0 Kudos
Message 3 of 3
(1,928 Views)