08-07-2018 12:29 PM - edited 08-07-2018 12:30 PM
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?
Solved! Go to Solution.
08-07-2018 02:18 PM
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.
08-09-2018 05:00 PM
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